public ActionResult AddClick(long?itemId) { MyItem itemName = new MyItem(); HttpCookie cookie = Request.Cookies["UserId"]; long longCookie; CookieCheker TheCheker = new CookieCheker(); if (TheCheker.Cheker(cookie, out longCookie)) { using (MyDbEntity db = new MyDbEntity()) { foreach (var itemDb in db.Items) { if (itemId == itemDb.ItemId) { itemDb.UserId = longCookie; } } db.SaveChanges(); } return(View("AddToBasket")); } return(View("NoUser")); }
public ActionResult Registration(MyUser newUser) { if (ModelState.IsValid) { User userInDB = new User() { FirstName = newUser.FirstName, LastName = newUser.LastName, Email = newUser.Email, Pass = newUser.Pass, BirthDate = newUser.BirthDate }; using (var context = new MyDbEntity()) { context.Users.Add(userInDB); context.SaveChanges(); } return(View("EndRegistration", newUser)); } else { return(View()); } }
public ActionResult UpdateItem(MyItem newItem) { MyUser userClass = new MyUser(); Item sendItem = new Item(); HttpCookie cookie = Request.Cookies["UserId"]; long longCookie; CookieCheker TheCheker = new CookieCheker(); if (TheCheker.Cheker(cookie, out longCookie)) { if (ModelState.IsValid) { Item itemInDb = new Item() { StatusSail = false, OwnerId = longCookie, Title = newItem.Title, Price = Convert.ToDecimal(newItem.Price), ShortDescription = newItem.ShortDescription, LongDescription = newItem.LongDescription, Date = DateTime.Now, PicLink1 = Converter(newItem.PicLink1), PicLink2 = Converter(newItem.PicLink2), PicLink3 = Converter(newItem.PicLink3) }; sendItem = itemInDb; } using (MyDbEntity dbUpdate = new MyDbEntity()) { dbUpdate.Items.Add(sendItem); dbUpdate.SaveChanges(); } return(View("EndUpdateItem", newItem)); } return(View("NoUser")); }