public ActionResult DeleteConfirmed(int id) { ProductColorSize productDb = db.ProductColorSize.Find(id); db.ProductColorSize.Remove(productDb); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind(Include = "ProductId,ColorId,Amount")] ProductColorSize productS, int SizeId) { ViewBag.products = db.Products.ToList(); ViewBag.colors = db.Colors.ToList(); if (ModelState.IsValid) { if (productS.ProductId == 0) { ModelState.AddModelError("allError", "No product selected"); return(View(productS)); } Product product = db.Products.Find(productS.ProductId); if (product == null) { ModelState.AddModelError("allError", "Product is not valid"); return(View(productS)); } if (SizeId == 0) { ModelState.AddModelError("allError", "Size must be selected"); return(View(productS)); } Size size = db.Sizes.Find(SizeId); productS.SizeId = size.Id; if (size == null) { ModelState.AddModelError("allError", "Size is not valid"); return(View(productS)); } if (productS.ColorId == 0) { ModelState.AddModelError("allError", "Color must be selected"); return(View(productS)); } Color color = db.Colors.Find(productS.ColorId); if (size == null) { ModelState.AddModelError("allError", "Color is not valid"); return(View(productS)); } if (productS.Amount == 0) { ModelState.AddModelError("allError", "Product amount must be included"); return(View(productS)); } db.ProductColorSize.Add(productS); await db.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductColorSize product = db.ProductColorSize.Find(id); if (product == null) { return(HttpNotFound()); } return(View(product)); }
public async Task <ActionResult> Edit(ProductCS_VM vM, ProductColorSize productColorSize) { productColorSize.ProductId = vM.ProductSize.ProductId; productColorSize.Amount = vM.ProductSize.Amount; ViewBag.colors = db.Colors.ToList(); if (productColorSize.Id == 0) { ModelState.AddModelError("allError", "Product Id is not found"); return(View(vM)); } var productDb = db.ProductColorSize.Find(productColorSize.Id); if (productDb == null) { ModelState.AddModelError("allError", "Product is not found"); return(View(vM)); } productColorSize.ProductId = productDb.ProductId; if (productColorSize.SizeId == 0 || productColorSize.ColorId == 0) { ModelState.AddModelError("allError", "Size id or color id is not found"); return(View(vM)); } productDb.ProductId = productColorSize.ProductId; productDb.SizeId = productColorSize.SizeId; productDb.ColorId = productColorSize.ColorId; productDb.Amount = productColorSize.Amount; await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ProductColorSize GetStyleColorSize(string bname, string pcode) { using (var dbContext = new SysProcessEntities()) { var query = from product in dbContext.Product from style in dbContext.ProStyle where product.StyleID == style.ID && style.Code == pcode from color in dbContext.ProColor where product.ColorID == color.ID from size in dbContext.ProSize where product.SizeID == size.ID select new { ColorName = color.Name, SizeName = size.Name, SizeID = size.ID }; var data = query.ToList(); var pcs = new ProductColorSize(); pcs.ColorNames = data.Select(o => o.ColorName).Distinct(); pcs.SizeNames = data.OrderBy(o => o.SizeID).Select(o => o.SizeName).Distinct(); return(pcs); } }
public Product_Stock_ColorSize GetStocks(string bname, string pcode) { using (var dbContext = new DistributionEntities()) { var query = from stock in dbContext.Stock from product in dbContext.ViewProduct where stock.ProductID == product.ProductID && product.StyleCode == pcode && stock.Quantity > 0 from storage in dbContext.Storage where stock.StorageID == storage.ID from organization in dbContext.ViewOrganization where organization.ID == storage.OrganizationID && organization.Name.EndsWith("店") from color in dbContext.ViewProColor where color.ID == product.ColorID from size in dbContext.ViewProSize where size.ID == product.SizeID select new { StyleCode = product.StyleCode, ProductCode = product.ProductCode, ColorName = color.Name, ShopID = organization.ID, Quantity = stock.Quantity, SizeID = size.ID, SizeName = size.Name }; var data = query.GroupBy(o => new { o.ShopID, o.StyleCode, o.ProductCode, o.ColorName, o.SizeName, o.SizeID }).Select( g => new { ColorName = g.Key.ColorName, ShopID = g.Key.ShopID, Quantity = g.Sum(o => o.Quantity), SizeID = g.Key.SizeID, SizeName = g.Key.SizeName, StyleCode = g.Key.StyleCode, ProductCode = g.Key.ProductCode }).ToList(); data = data.OrderBy(o => o.ShopID).ThenBy(o => o.ColorName).ThenBy(o => o.SizeID).ToList(); var pcs = new ProductColorSize(); pcs.ColorNames = data.Select(o => o.ColorName).Distinct(); pcs.SizeNames = data.OrderBy(o => o.SizeID).Select(o => o.SizeName).Distinct(); var stocks = new List <ProductStock>(); foreach (var d in data) { var stock = stocks.FirstOrDefault(r => r.ShopID == d.ShopID && r.StyleCode == d.StyleCode); if (stock == null) { stock = new ProductStock { StyleCode = d.StyleCode, ShopID = d.ShopID }; stocks.Add(stock); } if (stock.ColorQuas == null) { stock.ColorQuas = new List <ColorQuantity>(); } var cqua = stock.ColorQuas.FirstOrDefault(c => c.ColorName == d.ColorName); if (cqua == null) { cqua = new ColorQuantity { ColorName = d.ColorName }; stock.ColorQuas.Add(cqua); } if (cqua.SizeQuas == null) { cqua.SizeQuas = new List <SizeQuantity>(); } var squa = cqua.SizeQuas.FirstOrDefault(s => s.SizeName == d.SizeName); if (squa == null)//当为null时添加,否则不做处理 { squa = new SizeQuantity { SizeName = d.SizeName, Quantity = d.Quantity }; cqua.SizeQuas.Add(squa); } } return(new Product_Stock_ColorSize { ColorSize = pcs, ShopStocks = stocks }); } }
// GET: Details public ActionResult Index(int?Id) { if (Id == null) { return(HttpNotFound()); } var user = Session["user"] as User; var product = db.Products.Find(Id); ProductColorSize productColorSize = db.ProductColorSize.Where(p => p.ProductId == Id).FirstOrDefault(); int sizeId = db.ProductColorSize.Where(p => p.ProductId == Id).FirstOrDefault().SizeId; List <Image> productImages = db.Images.Where(s => s.ProductId == Id).ToList(); List <int> productsSize = db.ProductColorSize.Where(i => i.ProductId == Id).ToList().DistinctBy(x => x.SizeId).Select(s => s.SizeId).ToList(); List <int> productsColor = db.ProductColorSize.Where(i => i.ProductId == Id && i.SizeId == sizeId).Select(s => s.ColorId).ToList(); List <Size> sizes = new List <Size>(); List <Color> colors = new List <Color>(); foreach (var item in db.Sizes) { foreach (var item2 in productsSize) { if (item.Id == item2) { sizes.Add(item); } } } foreach (var item in db.Colors) { foreach (var item2 in productsColor) { if (item.Id == item2) { colors.Add(item); } } } if (user == null) { Details_VM vm = new Details_VM { ProductSize = productColorSize, Images = productImages, Sizes = sizes, Colors = colors, Product = product }; } Details_VM vm2 = new Details_VM { ProductSize = productColorSize, Images = productImages, Sizes = sizes, Colors = colors, Product = product, User = Session["user"] as User, Favorites = db.Favorites.ToList() }; return(View(vm2)); }