public ActionResult Claim([Bind(Include = "Id,Name,Cost")] Reward reward) { if (ModelState.IsValid) { string usrid = User.Identity.GetUserId(); var stars = from r in db_star.Star select r; var u_star = stars.Where(r => r.UserId.Equals(usrid)).ToList().First(); var id = reward.Id; Reward m_reward = db.Rewards.Find(id); if (u_star.Amount >= m_reward.Cost) { u_star.Amount -= m_reward.Cost; db_star.Entry(u_star).State = EntityState.Modified; db_star.SaveChanges(); ViewData["totalstar"] = u_star.Amount; ViewBag.Message = String.Format(reward.Name, "has been exchanged successfully!", DateTime.Now.ToString()); //System.Windows.Forms.MessageBox.Show(""); return(View(m_reward)); } else { ViewData["totalstar"] = u_star.Amount; ViewBag.Message = String.Format("You need more stars to exchange ", reward.Name); //System.Windows.Forms.MessageBox.Show(""); return(View(m_reward)); } } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,UserId,Amount")] Star star) { if (ModelState.IsValid) { db.Entry(star).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(star)); }
public ActionResult Create([Bind(Include = "Id,Name,Location,Duration,Star,UserId")] Record record) { if (ModelState.IsValid) { db.Record.Find(db.Record.Count()); record.Id = db.Record.Count() * 5; record.UserId = User.Identity.GetUserId(); db.Record.Add(record); db.SaveChanges(); var star = from r in db_star.Star select r; var u_star = star.Where(r => r.UserId.Equals(record.UserId)).ToList().First(); u_star.Amount += record.Star; db_star.Entry(u_star).State = EntityState.Modified; db_star.SaveChanges(); return(RedirectToAction("Index")); } return(View(record)); }