clean things up
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user