public ActionResult Index() { string usrid = User.Identity.GetUserId(); var stars = from r in db_star.Star select r; var starlst = stars.Where(r => r.UserId.Equals(usrid)).ToList(); if (starlst.Count == 0) { if (ModelState.IsValid) { Star newStar = new Star(); newStar.Amount = 0; newStar.UserId = usrid; db_star.Star.Add(newStar); db_star.SaveChanges(); ViewData["totalstar"] = 0; } } else { ViewData["totalstar"] = starlst.First().Amount; } return(View(db.Rewards.ToList())); }
public ActionResult Create([Bind(Include = "Id,UserId,Amount")] Star star) { if (ModelState.IsValid) { db.Star.Add(star); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(star)); }