public RedirectToRouteResult DeleteCredit(Guid creditId) { var credit = (from cat in MvcMarketDataContext.Credits where cat.CreditId == creditId select cat).FirstOrDefault(); MvcMarketDataContext.Credits.DeleteOnSubmit(credit); MvcMarketDataContext.SubmitChanges(); TempData["message"] = credit.CreditId + " با موفقیت حذف شد."; return(RedirectToAction("Credits")); }
public ActionResult UCart(Guid cartId, short status) { var cart = MvcMarketDataContext.Carts.FirstOrDefault(cat => cat.CartId == cartId); if (cart != null) { cart.Status = status; MvcMarketDataContext.SubmitChanges(); TempData["message"] = cart.CartId + " با موفقیت ذخیره شد."; return(RedirectToAction("Carts")); } return(View("Carts/Edit", cart)); }
public RedirectToRouteResult DeleteCategory(Guid categoryId) { var category = (from cat in MvcMarketDataContext.Categories where cat.CategoryId == categoryId select cat).First(); var catsOfProd = MvcMarketDataContext.CategoriezedProducts.Where(catprod => catprod.CategoryId == categoryId); MvcMarketDataContext.CategoriezedProducts.DeleteAllOnSubmit(catsOfProd); MvcMarketDataContext.Categories.DeleteOnSubmit(category); MvcMarketDataContext.SubmitChanges(); TempData["message"] = category.Name + " با موفقیت حذف شد."; return(RedirectToAction("Categories")); }
public ActionResult Category(Guid categoryId, string name) { var category = categoryId == Guid.Empty ? new Category() : MvcMarketDataContext.Categories.First(cat => cat.CategoryId == categoryId); if (ModelState.IsValid) { category.Name = name; if (category.CategoryId == Guid.Empty) { category.CategoryId = Guid.NewGuid(); MvcMarketDataContext.Categories.InsertOnSubmit(category); } MvcMarketDataContext.SubmitChanges(); TempData["message"] = category.Name + " با موفقیت ذخیره شد."; return(RedirectToAction("Categories")); } return(View("Categories/Edit", category)); }
public ActionResult SubmitCredit(Guid creditId) { var credit = MvcMarketDataContext.Credits.FirstOrDefault(c => c.CreditId == creditId && c.Expired == false); var shippingDetails = MvcMarketDataContext.ShippingDetails.FirstOrDefault(sd => sd.UserId == UserId); if (credit != null) { shippingDetails.CreditAmount += credit.Amount; credit.Expired = true; MvcMarketDataContext.SubmitChanges(); ViewData["CurrentAmount"] = shippingDetails.CreditAmount; TempData["message"] = string.Format("کاربر گرامی مبلغ {0} دلار به حساب شما واریز شد.", credit.Amount); return(View()); } ViewData["CurrentAmount"] = shippingDetails.CreditAmount; TempData["message"] = "اعتباری با شماره مذکور یافت نشد."; return(View()); }
public ActionResult Credit(Guid creditId, decimal amount, bool expired) { var credit = creditId == Guid.Empty ? new Credit() : MvcMarketDataContext.Credits.FirstOrDefault(cat => cat.CreditId == creditId); if (ModelState.IsValid) { credit.Amount = amount; credit.Expired = expired; if (credit.CreditId == Guid.Empty) { credit.CreditId = Guid.NewGuid(); MvcMarketDataContext.Credits.InsertOnSubmit(credit); } MvcMarketDataContext.SubmitChanges(); TempData["message"] = credit.CreditId + " با موفقیت ذخیره شد."; return(RedirectToAction("Credits")); } return(View("Credits/Edit", credit)); }
public RedirectToRouteResult DeleteProduct(Guid productId) { var product = (from p in MvcMarketDataContext.Products where p.ProductId == productId select p).FirstOrDefault(); if (product != null) { var catsOfProd = MvcMarketDataContext.CategoriezedProducts.Where(catprod => catprod.ProductId == productId); MvcMarketDataContext.CategoriezedProducts.DeleteAllOnSubmit(catsOfProd); var prodOnCartLines = MvcMarketDataContext.CartLines.Where(cl => cl.ProductId == productId); MvcMarketDataContext.CartLines.DeleteAllOnSubmit(prodOnCartLines); MvcMarketDataContext.Products.DeleteOnSubmit(product); MvcMarketDataContext.SubmitChanges(); TempData["message"] = product.Name + " با موفقیت حذف شد."; } TempData["message"] = product.Name + " با موفقیت حذف نشد."; return(RedirectToAction("Products")); }
public ActionResult DeleteUser(Guid userId) { MembershipUser user = null; if (userId != null && userId != Guid.Empty) { user = Membership.GetUser(userId); } if (user == null) { return(Content("User not found")); } var userCarts = MvcMarketDataContext.Carts.Where(c => c.UserId == userId); if (userCarts != null) { foreach (var cart in userCarts) { MvcMarketDataContext.CartLines.DeleteAllOnSubmit(MvcMarketDataContext.CartLines.Where(cl => cl.CartId == cart.CartId)); } MvcMarketDataContext.Carts.DeleteAllOnSubmit(userCarts); } var shD = MvcMarketDataContext.ShippingDetails.FirstOrDefault(sd => sd.UserId == userId); if (shD != null) { MvcMarketDataContext.ShippingDetails.DeleteOnSubmit(shD); MvcMarketDataContext.SubmitChanges(); } Membership.DeleteUser(user.UserName, true); TempData["message"] = user.UserName + " با موفقیت حذف شد."; return(RedirectToAction("Users")); }
public ActionResult ShippingDetails(ShippingDetails shippingDetails, string returnUrl) { if (ModelState.IsValid) { try { if (MvcMarketDataContext.ShippingDetails.FirstOrDefault(sd => sd.UserId == UserId) == null) { shippingDetails.UserId = UserId; MvcMarketDataContext.ShippingDetails.InsertOnSubmit(shippingDetails); MvcMarketDataContext.SubmitChanges(); } else { var shD = MvcMarketDataContext.ShippingDetails.FirstOrDefault(sd => sd.UserId == UserId); //Update MvcMarketDataContext.SubmitChanges(); } if (returnUrl != null) { return(Redirect(returnUrl)); } else { return(View("Success")); } } catch { ViewData["lastOperationFailed"] = true; return(View()); } } else { ViewData["lastOperationFailed"] = true; return(View()); } }
public ActionResult Product(Guid productId, string name, string description, decimal price, string[] categories, HttpPostedFileBase image) { Product product = null; var isNew = false; if (productId != null && productId != Guid.Empty) { product = MvcMarketDataContext.Products.FirstOrDefault(pr => pr.ProductId == productId); } if (product == null) { isNew = true; product = new Product(); } if (ModelState.IsValid) { Guid oldCatId = Guid.Empty; if (!isNew) { oldCatId = (from prod in MvcMarketDataContext.Products join catprod in MvcMarketDataContext.CategoriezedProducts on prod.ProductId equals catprod.ProductId join cat in MvcMarketDataContext.Categories on catprod.CategoryId equals cat.CategoryId where prod.Name == name select cat.CategoryId).FirstOrDefault(); } if (image != null) { product.ImageMimeType = image.ContentType; product.ImageData = new Binary(new byte[image.ContentLength]); image.InputStream.Read(product.ImageData.ToArray(), 0, image.ContentLength); } product.Name = name; product.Description = description; product.Price = price; var catId = Guid.Parse(categories[0]); if (!isNew && catId != oldCatId) { var cp1 = MvcMarketDataContext.CategoriezedProducts.FirstOrDefault( cp => cp.CategoryId == oldCatId && cp.ProductId == productId); if (cp1 != null) { MvcMarketDataContext.CategoriezedProducts.DeleteOnSubmit(cp1); } } if (isNew) { product.ProductId = Guid.NewGuid(); MvcMarketDataContext.Products.InsertOnSubmit(product); } if (MvcMarketDataContext.CategoriezedProducts.FirstOrDefault(c => c.ProductId == productId && c.CategoryId == catId) == null) { MvcMarketDataContext.CategoriezedProducts.InsertOnSubmit(new CategoriezedProduct { ProductId = product.ProductId, CategoryId = catId }); } MvcMarketDataContext.SubmitChanges(); TempData["message"] = product.Name + " با موفقیت ذخیره شد."; return(RedirectToAction("Products")); } return(View("Products/Edit", product)); }