public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { User user = null; using (TimurContext db = new TimurContext()) { user = db.Users.FirstOrDefault(u => u.Login == model.Name); } if (user == null) { using (TimurContext db = new TimurContext()) { db.Users.Add(new User { Login = model.Name, Password = model.Password, RoleId = 2 }); db.SaveChanges(); user = db.Users.Where(u => u.Login == model.Name && u.Password == model.Password).FirstOrDefault(); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Данный логин не доступен"); } } return(View(model)); }
public ActionResult UpBalance(string card, int sum) { using (var context = new TimurContext()) { var name = User.Identity.Name; User u1 = db.Users.FirstOrDefault(u => u.Login == name); int z = u1.Id; User u2 = new User { Id = z }; Bill bill = new Bill(); bill.Card_number = card; bill.Balance = sum; u2.Bills.Add(bill); context.SaveChanges(); } return(RedirectToAction("GetUser", "Home")); }
public ActionResult Buy(int x) { using (var context = new TimurContext()) { var name = User.Identity.Name; User u1 = db.Users.FirstOrDefault(u => u.Login == name); int z = u1.Id; User u2 = new User { Id = z }; context.Users.Add(u2); context.Users.Attach(u2); Film f1 = new Film { Id = x }; context.Films.Add(f1); context.Films.Attach(f1); u2.Films.Add(f1); context.SaveChanges(); return(RedirectToAction("GetUser", "Home")); } }
public ActionResult CreateGenre(Genre genre) { db.Genres.Add(genre); db.SaveChanges(); return(RedirectToAction("GenreList", "Admin")); }