This commit is contained in:
tmont 2011-02-15 00:18:29 +00:00
parent cdd93afeff
commit 2496edaf89
6 changed files with 32 additions and 31 deletions

View File

@ -47,9 +47,10 @@ namespace VideoGameQuotes.Web.Controllers {
}
public ActionResult Recent() {
//get last 10 submitted quotes
var quotes = quoteService.GetMostRecentQuotes(10);
return View(new QuoteCollectionModel { Quotes = quotes, User = currentUserProvider.CurrentUser });
return View(new QuoteCollectionModel {
Quotes = quoteService.GetMostRecentQuotes(10),
User = currentUserProvider.CurrentUser
});
}
public ActionResult Best(int start = 0, int end = 19) {

View File

@ -0,0 +1,14 @@
using System;
namespace VideoGameQuotes.Web.Models {
public class PagedQuoteCollectionModel : QuoteCollectionModel {
public int Start { get; set; }
public int End { get; set; }
public int PageSize { get { return End - Start + 1; } }
public int NextStart { get { return End + 1; } }
public int NextEnd { get { return End + PageSize; } }
public int PreviousStart { get { return Math.Max(0, Start - PageSize); } }
public int PreviousEnd { get { return Math.Max(PageSize - 1, End - PageSize); } }
public bool HasPrevious { get { return Start > 0; } }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Models {
public class QuoteCollectionModel {
public IEnumerable<Quote> Quotes { get; set; }
public User User { get; set; }
}
}

View File

@ -1,36 +1,12 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using JetBrains.Annotations;
using VideoGameQuotes.Api;
namespace VideoGameQuotes.Web.Models {
public class QuoteCollectionModel {
public IEnumerable<Quote> Quotes { get; set; }
public User User { get; set; }
}
public class PagedQuoteCollectionModel : QuoteCollectionModel {
public int Start { get; set; }
public int End { get; set; }
public int PageSize { get { return End - Start + 1; } }
public int NextStart { get { return End + 1; } }
public int NextEnd { get { return End + PageSize; } }
public int PreviousStart { get { return Math.Max(0, Start - PageSize); } }
public int PreviousEnd { get { return Math.Max(PageSize - 1, End - PageSize); } }
public bool HasPrevious { get { return Start > 0; } }
}
public class QuoteModel {
[NotNull]
public Quote Quote { get; set; }
public User User { get; set; }
public bool VotedUp {
get { return Quote.VotedFor(User) == VoteDirection.Up; }
}
public bool VotedDown {
get { return Quote.VotedFor(User) == VoteDirection.Down; }
}
public bool VotedUp { get { return Quote.VotedFor(User) == VoteDirection.Up; } }
public bool VotedDown { get { return Quote.VotedFor(User) == VoteDirection.Down; } }
}
}

View File

@ -23,7 +23,6 @@ namespace VideoGameQuotes.Web.Services {
Quote GetRandomQuote();
IEnumerable<Quote> GetBestQuotes(int start, int end);
Vote SaveVote(Vote vote);
[NotNull]
Vote GetVoteOrCreateNew(Quote quote, User voter);
}

View File

@ -85,6 +85,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Models\PagedQuoteCollectionModel.cs" />
<Compile Include="Models\QuoteCollectionModel.cs" />
<Compile Include="Models\QuoteModel.cs" />
<Compile Include="Models\VoteModel.cs" />
<Compile Include="Validation\NonEmptyText.cs" />