no longer use ajax, make sure you don't go over 15 influence
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,7 +18,7 @@ bld/
|
||||
.vs
|
||||
# Roslyn cache directories
|
||||
*.ide/
|
||||
|
||||
**/PublishProfiles/**
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace NetrunnerChallenge.Data
|
||||
{
|
||||
public IList<Cards> 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<OneCard> 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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<int> em)
|
||||
{
|
||||
var total = 0;
|
||||
em.ForEach(a=> { total += a; });
|
||||
return total;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/NetrunnerChallenge/Migrations/201505231941109_4.Designer.cs
generated
Normal file
29
src/NetrunnerChallenge/Migrations/201505231941109_4.Designer.cs
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
// <auto-generated />
|
||||
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"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/NetrunnerChallenge/Migrations/201505231941109_4.cs
Normal file
24
src/NetrunnerChallenge/Migrations/201505231941109_4.cs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
126
src/NetrunnerChallenge/Migrations/201505231941109_4.resx
Normal file
126
src/NetrunnerChallenge/Migrations/201505231941109_4.resx
Normal file
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
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zpVOd5dJtkTnEIEYDNUBZct/THNCSB4vuqmau1kZAhrkgApS2FTASXa0XpJqaWhAr1qcj8gKOEADF+S2foGe/C2yeOP+Il8tflG0A7kX5D1NU+ugjRkqGIFzQ2++ETMBxEq/d/A8379+FkKwAA</value>
|
||||
</data>
|
||||
<data name="DefaultSchema" xml:space="preserve">
|
||||
<value>dbo</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -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<ChallengeCard> 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();
|
||||
} }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -184,6 +184,10 @@
|
||||
<Compile Include="Migrations\201505210212299_3.Designer.cs">
|
||||
<DependentUpon>201505210212299_3.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\201505231941109_4.cs" />
|
||||
<Compile Include="Migrations\201505231941109_4.Designer.cs">
|
||||
<DependentUpon>201505231941109_4.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Models\ChallengeCard.cs" />
|
||||
<Compile Include="Models\Challenge.cs" />
|
||||
@@ -207,6 +211,7 @@
|
||||
<Content Include="fonts\glyphicons-halflings-regular.eot" />
|
||||
<Content Include="Content\bootstrap-theme.css.map" />
|
||||
<Content Include="Content\bootstrap.css.map" />
|
||||
<None Include="Properties\PublishProfiles\NetrunnerChallenge.pubxml" />
|
||||
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
|
||||
<Content Include="Icon.png" />
|
||||
<Content Include="Scripts\bootstrap.js" />
|
||||
@@ -259,6 +264,9 @@
|
||||
<EmbeddedResource Include="Migrations\201505210212299_3.resx">
|
||||
<DependentUpon>201505210212299_3.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Migrations\201505231941109_4.resx">
|
||||
<DependentUpon>201505231941109_4.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
<div class="form-horizontal">
|
||||
<h4>Generate your next Deckbuilder Challenge!</h4>
|
||||
@@ -36,13 +31,14 @@
|
||||
@section Scripts {
|
||||
@Scripts.Render("~/bundles/jqueryval")
|
||||
<script>
|
||||
var start = function() {
|
||||
$('#subBtn').attr("disabled", "disabled");
|
||||
$('#loadingGif').show();
|
||||
};
|
||||
|
||||
|
||||
$(document).ready(function (){
|
||||
$('#loadingGif').hide();
|
||||
$('#subBtn').submit(function () {
|
||||
$('#loadingGif').show();
|
||||
$('#subBtn').attr("disabled", "disabled");
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user