public ActionResult Basket() { HttpCookie cookie = Request.Cookies["UserId"]; long longCookie; CookieCheker TheCheker = new CookieCheker(); List <Item> itemList = new List <Item>(); if (TheCheker.Cheker(cookie, out longCookie)) { using (MyDbEntity db = new MyDbEntity()) { foreach (var itemInDb in db.Items) { if (itemInDb.UserId == longCookie) { itemList.Add(itemInDb); } } } return(View("Basket", itemList)); // return View("NoItemInBasket"); } return(View("NoUser")); }
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 UserLogin(MyUser userClass) { if (userClass.Email != null && userClass.Pass != null) { using (MyDbEntity db = new MyDbEntity()) { foreach (var userInDb in db.Users) { if (userInDb.Email == userClass.Email && userInDb.Pass == userClass.Pass) { HttpCookie cookie2 = new HttpCookie("UserId", userInDb.UserId.ToString()); cookie2.Expires = DateTime.Now.AddMinutes(10); Response.Cookies.Add(cookie2); return(View("StatusUser", userClass)); } } } } 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")); }
public bool Cheker(HttpCookie cookie, out long userCookieUserIdLong) { if (cookie != null) { if (long.TryParse(cookie.Value, out userCookieUserIdLong)) { MyUser userClass = new MyUser(); using (MyDbEntity db = new MyDbEntity()) { foreach (var userInDb in db.Users) { if (userInDb.UserId == userCookieUserIdLong) { return(true); } } } } } userCookieUserIdLong = 0; return(false); }
//public ActionResult Logout() //{ // if (Request.Cookies["StudentCookies"] != null) // { // HttpCookie StudentCookies = new HttpCookie("StudentCookies", userClass.UserEmail); // StudentCookies.Expires = DateTime.Now.AddMinutes(-10); // Response.Cookies.Add(StudentCookies); // } // return RedirectToAction("Index", controllerName: "Home"); //} public ActionResult StatusUserBar() { HttpCookie cookie = Request.Cookies["UserId"]; long longCookie; CookieCheker TheCheker = new CookieCheker(); if (TheCheker.Cheker(cookie, out longCookie)) { MyUser userClass = new MyUser(); using (MyDbEntity db = new MyDbEntity()) { foreach (var userInDb in db.Users) { if (userInDb.UserId == longCookie) { userClass.UserName = userInDb.FirstName + " " + userInDb.LastName; } } return(View("StatusUserBar", userClass)); } } return(View("NoUserLogedIn")); }
public void Delete(IUnitOfWork uow, MyDbEntity entity) { uow.Database.Delete(entity); }
public void Save(IUnitOfWork uow, MyDbEntity entity) { uow.Database.Save(entity); }