public ActionResult Index(SimpleStatsModel simplestatsmodel)
 {
     using (var db = new HearthstoneContext())
     {
         if (ModelState.IsValid)
         {
             var user = (from u in db.UserProfiles.Include("SimpleStats")
                         where u.UserName == User.Identity.Name
                         select u).FirstOrDefault();
             simplestatsmodel.UserID = user.UserId;
             //if ID is 0, need to add, not update
             if (simplestatsmodel.SimpleStatsID == 0)
             {
                 db.SimpleStats.Add(simplestatsmodel);
             }
             else
             {
                 var ssm = db.SimpleStats.Find(simplestatsmodel.SimpleStatsID);
                 simplestatsmodel.CopyTo(ssm);
                 db.Entry(ssm).State = EntityState.Modified;
             }
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(simplestatsmodel);
     }
 }
 public ActionResult Index()
 {
     using (var db = new HearthstoneContext())
     {
         var user = (from u in db.UserProfiles.Include("SimpleStats")
                     where u.UserName == User.Identity.Name
                     select u).FirstOrDefault();
         var simplestats = user.SimpleStats.FirstOrDefault();
         if (simplestats == null) simplestats = new SimpleStatsModel();
         return View(simplestats);
     }
 }
예제 #3
0
 internal void CopyTo(SimpleStatsModel rhs)
 {
     rhs.BaseLosses = this.BaseLosses;
     rhs.BaseWins = this.BaseWins;
     rhs.DrawLosses = this.DrawLosses;
     rhs.DrawWins = this.DrawWins;
     rhs.DruidLosses = this.DruidLosses;
     rhs.DruidLossesAgainst = this.DruidLossesAgainst;
     rhs.DruidWins = this.DruidWins;
     rhs.DruidWinsAgainst = this.DruidWinsAgainst;
     rhs.HunterLosses = this.HunterLosses;
     rhs.HunterLossesAgainst = this.HunterLossesAgainst;
     rhs.HunterWins = this.HunterWins;
     rhs.HunterWinsAgainst = this.HunterWinsAgainst;
     rhs.MageLosses = this.MageLosses;
     rhs.MageLossesAgainst = this.MageLossesAgainst;
     rhs.MageWins = this.MageWins;
     rhs.MageWinsAgainst = this.MageWinsAgainst;
     rhs.PaladinLosses = this.PaladinLosses;
     rhs.PaladinLossesAgainst = this.PaladinLossesAgainst;
     rhs.PaladinWins = this.PaladinWins;
     rhs.PaladinWinsAgainst = this.PaladinWinsAgainst;
     rhs.PlayLosses = this.PlayLosses;
     rhs.PlayWins = this.PlayWins;
     rhs.PriestLosses = this.PriestLosses;
     rhs.PriestLossesAgainst = this.PriestLossesAgainst;
     rhs.PriestWins = this.PriestWins;
     rhs.PriestWinsAgainst = this.PriestWinsAgainst;
     rhs.RogueLosses = this.RogueLosses;
     rhs.RogueLossesAgainst = this.RogueLossesAgainst;
     rhs.RogueWins = this.RogueWins;
     rhs.RogueWinsAgainst = this.RogueWinsAgainst;
     rhs.ShamanLosses = this.ShamanLosses;
     rhs.ShamanLossesAgainst = this.ShamanLossesAgainst;
     rhs.ShamanWins = this.ShamanWins;
     rhs.ShamanWinsAgainst = this.ShamanWinsAgainst;
     rhs.SimpleStatsID = this.SimpleStatsID;
     rhs.UserID = this.UserID;
     rhs.WarlockLosses = this.WarlockLosses;
     rhs.WarlockLossesAgainst = this.WarlockLossesAgainst;
     rhs.WarlockWins = this.WarlockWins;
     rhs.WarlockWinsAgainst = this.WarlockWinsAgainst;
     rhs.WarriorLosses = this.WarriorLosses;
     rhs.WarriorLossesAgainst = this.WarriorLossesAgainst;
     rhs.WarriorWins = this.WarriorWins;
     rhs.WarriorWinsAgainst = this.WarriorWinsAgainst;
 }