clean things up

This commit is contained in:
Tommy Parnell
2015-05-23 17:07:47 -04:00
parent d4c6703cab
commit c74a246ac1
3 changed files with 8 additions and 11 deletions

View File

@@ -15,6 +15,7 @@ namespace NetrunnerChallenge.Controllers
{
public class HomeController : Controller
{
[OutputCache(Duration = int.MaxValue)]
public ActionResult Index()
{
using (var db = new DatabaseContext())
@@ -30,6 +31,7 @@ namespace NetrunnerChallenge.Controllers
}
[OutputCache(Duration = int.MaxValue, VaryByParam = "id")]
/// <exception cref="NotImplementedException">Always.</exception>
public ActionResult Challenge(string id)
{
@@ -82,7 +84,8 @@ namespace NetrunnerChallenge.Controllers
}
var generator = new Generator();
string rnmId = null;
while (rnmId == null || db.ChallengeDb.ToList().Any(a => string.Equals(a.Id, rnmId)))
var currentChallenges = db.ChallengeDb.ToList();
while (rnmId == null || currentChallenges.Any(a => string.Equals(a.Id, rnmId)))
{
rnmId = generator.GenerateRandomString();
}

View File

@@ -8,6 +8,7 @@ namespace NetrunnerChallenge.Data
public class Generator
{
static readonly string Chars = "abcdefghijklmnopqrstuvwxyz0123456789";
public string GenerateRandomString()
{
var random = new Random();
@@ -16,15 +17,5 @@ namespace NetrunnerChallenge.Data
.Take(8)
.ToArray());
}
public T RandomEnumValue<T>()
{
var _Random = new Random();
return Enum
.GetValues(typeof(T))
.Cast<T>()
.OrderBy(x => _Random.Next())
.FirstOrDefault();
}
}
}

View File

@@ -6,6 +6,9 @@ using NetrunnerDb.Net.Responses;
namespace NetrunnerChallenge.Data
{
/// <summary>
/// Wraps the netrunner API in a cache so we don't keep requesting data when we don't need to
/// </summary>
public class NetrunnerApi
{
public IList<Cards> GetCards()