Пример #1
0
        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()));
        }
Пример #2
0
        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));
        }