diff --git a/.gitignore b/.gitignore index 522575b..14b27e6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ bld/ .vs # Roslyn cache directories *.ide/ - +**/PublishProfiles/** # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* diff --git a/src/NetrunnerChallenge/Controllers/HomeController.cs b/src/NetrunnerChallenge/Controllers/HomeController.cs index 9b42010..3b1df96 100644 --- a/src/NetrunnerChallenge/Controllers/HomeController.cs +++ b/src/NetrunnerChallenge/Controllers/HomeController.cs @@ -100,14 +100,27 @@ namespace NetrunnerChallenge.Controllers var randgen = new Random(); for (int i = 0; i < cardAmount; i++) { + var index = randgen.Next(length); - var chal = new ChallengeCard {Code = cards[index].Code}; + var choice = cards[index]; + while ((challenge.CurrentInfluence + + (string.Equals(choice.Faction, challenge.Faction.FactionName, + StringComparison.CurrentCultureIgnoreCase) + ? 0 + : choice.Factioncost)) > 15) + { + index = randgen.Next(length); + choice = cards[index]; + } + + + var chal = new ChallengeCard {Code = choice.Code, Faction = choice.Faction, FactionCosts = choice.Factioncost}; db.Entry(chal).State = EntityState.Added; challenge.Cards.Add(chal); } db.ChallengeDb.Add(challenge); db.SaveChanges(); - return Challenge(challenge.Id); + return RedirectToAction("Challenge", "Home", new {id = challenge.Id}); } } } diff --git a/src/NetrunnerChallenge/Data/NetrunnerApi.cs b/src/NetrunnerChallenge/Data/NetrunnerApi.cs index af86a93..63def50 100644 --- a/src/NetrunnerChallenge/Data/NetrunnerApi.cs +++ b/src/NetrunnerChallenge/Data/NetrunnerApi.cs @@ -10,13 +10,13 @@ namespace NetrunnerChallenge.Data { public IList GetCards() { - return AppServices.Cache.Get("AllCards",DateTime.Today.AddDays(2), () => new Repository().GetCards()); + return AppServices.Cache.Get("AllCards",DateTime.Today.AddDays(5), () => new Repository().GetCards()); } public IList GetCard(string code) { - return AppServices.Cache.Get(code + "-Card", DateTime.Today.AddDays(2), () => new Repository().GetCard(code)); + return AppServices.Cache.Get(code + "-Card", DateTime.MaxValue, () => new Repository().GetCard(code)); } } diff --git a/src/NetrunnerChallenge/Extensions/CollectionExtension.cs b/src/NetrunnerChallenge/Extensions/CollectionExtension.cs index 5530e92..2235523 100644 --- a/src/NetrunnerChallenge/Extensions/CollectionExtension.cs +++ b/src/NetrunnerChallenge/Extensions/CollectionExtension.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; +using WebGrease.Css.Extensions; namespace NetrunnerChallenge.Extensions { @@ -18,5 +19,12 @@ namespace NetrunnerChallenge.Extensions var index = rand.Next(0, enumerable1.Count); return enumerable1.ElementAt(index); } + + public static int Combine(this IEnumerable em) + { + var total = 0; + em.ForEach(a=> { total += a; }); + return total; + } } } \ No newline at end of file diff --git a/src/NetrunnerChallenge/Migrations/201505231941109_4.Designer.cs b/src/NetrunnerChallenge/Migrations/201505231941109_4.Designer.cs new file mode 100644 index 0000000..e1b12b9 --- /dev/null +++ b/src/NetrunnerChallenge/Migrations/201505231941109_4.Designer.cs @@ -0,0 +1,29 @@ +// +namespace NetrunnerChallenge.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.2-31219")] + public sealed partial class _4 : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(_4)); + + string IMigrationMetadata.Id + { + get { return "201505231941109_4"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/src/NetrunnerChallenge/Migrations/201505231941109_4.cs b/src/NetrunnerChallenge/Migrations/201505231941109_4.cs new file mode 100644 index 0000000..323334f --- /dev/null +++ b/src/NetrunnerChallenge/Migrations/201505231941109_4.cs @@ -0,0 +1,24 @@ +using System.Linq; +using NetrunnerChallenge.Data; + +namespace NetrunnerChallenge.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class _4 : DbMigration + { + public override void Up() + { + AddColumn("dbo.ChallengeCards", "FactionCosts", c => c.Int()); + AddColumn("dbo.ChallengeCards", "Faction", c => c.String()); + + } + + public override void Down() + { + DropColumn("dbo.ChallengeCards", "Faction"); + DropColumn("dbo.ChallengeCards", "FactionCosts"); + } + } +} diff --git a/src/NetrunnerChallenge/Migrations/201505231941109_4.resx b/src/NetrunnerChallenge/Migrations/201505231941109_4.resx new file mode 100644 index 0000000..9604fa4 --- /dev/null +++ b/src/NetrunnerChallenge/Migrations/201505231941109_4.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAO1aS2/jNhC+F+h/EHRqF1nLSS7bwN5F6iSF0c0DcXbRW0BLtCOUolSSCmws+st66E/qX+hQD1qiKIl+ZJsWRS4WH8N5fDOc4eSvP/4cfVhFxHnGjIcxHbvHg6HrYOrHQUiXYzcVi7fv3A/vv/1mdBlEK+dzue5UroOdlI/dJyGSM8/j/hOOEB9Eoc9iHi/EwI8jDwWxdzIc/uAdH3sYSLhAy3FG9ykVYYSzD/icxNTHiUgRuY4DTHgxDjOzjKpzgyLME+TjsXuDBUspxWzyhAjBdIkHF0gg1zknIQJ2ZpgsXAdRGgskgNmzTxzPBIvpcpbAACIP6wTDugUiHBdCnG2W28ozPJHyeJuNJSk/5SKOtiR4fFooyNO376RmVykQVHgJqhZrKXWmxrGrFOc6+mlnE8LkSqOac9sM1MCR01x0pDACUJJ/R84kJSJleExxKhgiR85dOieh/zNeP8S/YjqmKSFVhoFlmKsNwNAdixPMxPoeLwoxpoHrePV9nr5RbavsyeUDSADEXecarT4C4+IJwH/yznWuw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2LNDsoB2iMB/BZW7RHzJf244TOkpleQKQ3waux+ybadOdNfHjc7j5xbBlA5c4bO71UG9njg7bjxvoatMh30PqBua7fKi34Jhu8itPq+W2d2r/YZxzuROQhL9StTB7wFmqoE6nhq95YDNBD+G8gyvNXvZc3qe/wWhF7wzf2wz+z5g+mOr+tAEsCAmbQVInCLc8HgHm/UGHcspH6YINKQpZnK2KBM6lfR1GcucIKphI9RVJsD+7J8dYIG/T5dvEgzQm8/btUh2AdhB8JCew3/ckiwOqw7kz84Bsw9mebrq2WnpLvfkue+kCvNYzB2HsTUdLMZ0NmP6W/HdJ5mbj+0tGy6+jWmU8r3pn+ym2NuV9g1K6r6NTx/vMKmjWao2mOblch26jpMP6ZZPIIDV/67ECIID5cbErIiptivua5aM6WLuIwiGkflEi23uMYCQbWCzpkIF6AjmPYx51nP/zMiKSy5jOY4mNLbVCSpAJFxNCe1/1eQkajr/KzpVOd5dJtkTnEIEYDNUBZct/THNCSB4vuqmau1kZAhrkgApS2FTASXa0XpJqaWhAr1qcj8gKOEADF+S2foGe/C2yeOP+Il8tflG0A7kX5D1NU+ugjRkqGIFzQ2++ETMBxEq/d/A8379+FkKwAA + + + dbo + + \ No newline at end of file diff --git a/src/NetrunnerChallenge/Models/Challenge.cs b/src/NetrunnerChallenge/Models/Challenge.cs index b170b73..bbfd65a 100644 --- a/src/NetrunnerChallenge/Models/Challenge.cs +++ b/src/NetrunnerChallenge/Models/Challenge.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Web; +using NetrunnerChallenge.Extensions; + namespace NetrunnerChallenge.Models { public class Challenge @@ -12,5 +15,12 @@ namespace NetrunnerChallenge.Models public ICollection Cards { get; set; } public Faction Faction { get; set; } public DateTime CreationDate { get; set; } + [NotMapped] + public int CurrentInfluence { + get + { + return Cards.Where(a => !string.Equals(Faction.FactionName, a.Faction) && a.FactionCosts.HasValue) + .Select(a => (int) a.FactionCosts).Combine(); + } } } } \ No newline at end of file diff --git a/src/NetrunnerChallenge/Models/ChallengeCard.cs b/src/NetrunnerChallenge/Models/ChallengeCard.cs index bd74523..d429e00 100644 --- a/src/NetrunnerChallenge/Models/ChallengeCard.cs +++ b/src/NetrunnerChallenge/Models/ChallengeCard.cs @@ -9,6 +9,8 @@ namespace NetrunnerChallenge.Models public class ChallengeCard { public string Code { get; set; } + public int? FactionCosts { get; set; } + public string Faction { get; set; } [Key] public int Id { get; set; } } diff --git a/src/NetrunnerChallenge/NetrunnerChallenge.csproj b/src/NetrunnerChallenge/NetrunnerChallenge.csproj index 03afa44..3d63f2f 100644 --- a/src/NetrunnerChallenge/NetrunnerChallenge.csproj +++ b/src/NetrunnerChallenge/NetrunnerChallenge.csproj @@ -184,6 +184,10 @@ 201505210212299_3.cs + + + 201505231941109_4.cs + @@ -207,6 +211,7 @@ + @@ -259,6 +264,9 @@ 201505210212299_3.cs + + 201505231941109_4.cs + 10.0 diff --git a/src/NetrunnerChallenge/Views/Home/Index.cshtml b/src/NetrunnerChallenge/Views/Home/Index.cshtml index 23c3d35..8b825c4 100644 --- a/src/NetrunnerChallenge/Views/Home/Index.cshtml +++ b/src/NetrunnerChallenge/Views/Home/Index.cshtml @@ -4,12 +4,7 @@ ViewBag.Title = "Home Page"; } - @using (Ajax.BeginForm("Generate", "Home", new AjaxOptions() - { - HttpMethod = "Post", - OnBegin = "start", - UpdateTargetId = "innerBody" - })) + @using (Html.BeginForm("Generate", "Home", FormMethod.Post)) {

Generate your next Deckbuilder Challenge!

@@ -36,13 +31,14 @@ @section Scripts { @Scripts.Render("~/bundles/jqueryval") }