public ActionResult AddToCard(int id) { Product product; product = context.Products .Include(p => p.User) .Where(p => p.ID == id) .FirstOrDefault(); User user = context.Users .FirstOrDefault(u => u.UserName == User.Identity.Name); if (user != null) { product.User = context.Users .Where(u => u.ID == user.ID) .FirstOrDefault(); context.Users.Attach(product.User); } product.Status = State.InCard; product.IsInCard = true; context.SaveChanges(); return(RedirectToAction("Home", "Home")); }
public ActionResult SubmitData(Product p) { HttpFileCollectionWrapper wrapper = HttpContext.Request.Files as HttpFileCollectionWrapper; p.Picture1 = GetByteArray(wrapper[0]); p.Picture2 = GetByteArray(wrapper[1]); p.Picture3 = GetByteArray(wrapper[2]); if (ModelState.IsValid) { User user = context.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); if (user != null) { p.Owner = context.Users.Where(u => u.ID == user.ID).FirstOrDefault(); context.Users.Attach(p.Owner); } p.Date = DateTime.Now; context.Products.Add(p); context.SaveChanges(); ViewBag.Message = "העלאת הקובץ הצליחה"; return(RedirectToAction("Home", "Home")); } return(View("AddProduct")); }
public ActionResult SubmitData(Product p) { HttpFileCollectionWrapper wrapper = HttpContext.Request.Files as HttpFileCollectionWrapper; p.picture1 = GetByteArray(wrapper[0]); p.picture2 = GetByteArray(wrapper[1]); p.picture3 = GetByteArray(wrapper[2]); if (ModelState.IsValid) { using (var ctx = new BuyForUDB()) { User user = ctx.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); if (user != null) { p.Owner = ctx.Users.Where(u => u.Id == user.Id).FirstOrDefault(); ctx.Users.Attach(p.Owner); } p.Date = DateTime.Now; ctx.Product.Add(p); ctx.SaveChanges(); ViewBag.Message = "File uploaded successfully"; } return(RedirectToAction("HomePage", "Home")); } return(View("AddProduct")); }
public ViewResult EditUser(User user) { if (ModelState.IsValid) { User chkUser = context.Users .Where(User => User.UserName == user.UserName) .FirstOrDefault(); if (!User.Identity.IsAuthenticated) { if (chkUser == null) { context.Users.Add(user); context.SaveChanges(); ViewBag.Message = "פרטי משתמש נקלטו בהצלחה"; return(View("EditUser")); } else { ViewBag.Message = "שם משתמש תפוס"; return(View("EditUser")); } } else { chkUser.FirstName = user.FirstName; chkUser.LastName = user.LastName; chkUser.BirthDate = user.BirthDate; chkUser.Email = user.Email; chkUser.UserName = user.UserName; chkUser.Password = user.Password; chkUser.ConfirmPassword = user.ConfirmPassword; context.SaveChanges(); ViewBag.Message = "העדכון עבר בהצלחה"; return(View("EditUser")); } } return(View("EditUser", new User())); }
public decimal RemoveFromCart(int id) { Product item; using (var ctx = new BuyForUDB()) { item = ctx.Product.Include(p => p.User).Where(p => p.Id == id).FirstOrDefault(); item.UserId = null; item.Status = State.ForSale; item.IsInCart = false; ctx.SaveChanges(); } return(item.Price); }
public ViewResult EditUser(User u) { if (ModelState.IsValid) { using (var ctx = new BuyForUDB()) { var ExistsUser = ctx.Users.Where(User => User.UserName == u.UserName).FirstOrDefault(); if (!User.Identity.IsAuthenticated) { if (ExistsUser == null) { ctx.Users.Add(u); ctx.SaveChanges(); ViewBag.Massege = "פרטי משתמש נקלטו בהצלחה"; // return RedirectToAction("HomePage", "Home"); return(View("EditUser")); } else { ViewBag.Massege = "שם משתמש כבר קיים !!!"; return(View("EditUser")); } } else { ExistsUser.ConfirmPassword = u.ConfirmPassword; ctx.Users.AddOrUpdate(u); ctx.SaveChanges(); ViewBag.Massege = "העדכון הצליח"; return(View("EditUser")); // return RedirectToAction("HomePage", "Home"); } } } return(View("EditUser", new User())); }
public ActionResult Sale() { var ItemToSale = new List <Product>(); using (var ctx = new BuyForUDB()) { ItemToSale = ctx.Product.Where(p => p.Status == State.ShoppingCart && p.User.UserName == User.Identity.Name).ToList(); foreach (var item in ItemToSale) { item.Status = State.Sold; } ctx.SaveChanges(); ViewBag.Massege1 = "תודה על קניתך"; return(RedirectToAction("HomePage", "Home")); } }
public ActionResult AddToCart(int id) { Product item; using (var ctx = new BuyForUDB()) { item = ctx.Product.Include(p => p.User).Where(p => p.Id == id).FirstOrDefault(); User user = ctx.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); if (user != null) { item.User = ctx.Users.Where(u => u.Id == user.Id).FirstOrDefault(); ctx.Users.Attach(item.User); } item.Status = State.ShoppingCart; item.IsInCart = true; ctx.SaveChanges(); } return(RedirectToAction("HomePage", "Home")); }