public async Task <IActionResult> Update([FromRoute] Int64 id, [FromBody] UpdateProductColorRequest productColorRequest) { var prodColor = new ProductColors { Id = id, ArabicName = productColorRequest.ArabicName, EnglishName = productColorRequest.EnglishName, HexCode = productColorRequest.HexCode, UpdatedAt = DateTime.Now }; var status = await _productColorService.UpdateProductColorsAsync(prodColor); if (status == -1) { return(Conflict(new ErrorResponse { message = "Dublicate Entry", status = Conflict().StatusCode })); } if (status == 1) { return(Ok(prodColor)); } return(NotFound(new ErrorResponse { message = "Not Found", status = NotFound().StatusCode })); }
public void FillDDLsUpdate(Guid productId, int selectedColorId) { using (MashadCarpetEntities db = new MashadCarpetEntities()) { List <ProductColors> productColors = db.ProductColors.Where(current => current.fk_ProductID == productId).ToList(); ddlColors.Items.Clear(); ddlColors.Items.Add(new ListItem("رنگ ", "-1")); foreach (var i in productColors) { ddlColors.Items.Add(new ListItem(i.Colors.ColorTitle, i.Colors.ColorID.ToString())); } ProductColors selectedProductColor = productColors.Where(current => current.fk_ColorID == selectedColorId).FirstOrDefault(); List <ProductColorSizes> productColorSizes = db.ProductColorSizes .Where(current => current.fk_ProductColorID == selectedProductColor.ProductColorID).ToList(); ddlSize.Items.Clear(); ddlSize.Items.Add(new ListItem("سایز ", "-1")); foreach (var i in productColorSizes) { ddlSize.Items.Add(new ListItem(i.SIzes.SizeTitle, i.SIzes.SizeID.ToString())); } } }
// public Nullable<Boolean> ReturnThumb() // { // if (ddlThumbImg.SelectedValue == "0") // return null; // else if (ddlThumbImg.SelectedValue == "1") // return true; // else // return false; // } public void InsertForm() { Guid ProductID = new Guid(ViewState["ID"].ToString()); string new_filename = string.Empty; if (fuImg.PostedFile.ContentLength != 0) { string original_filename = Path.GetFileName(fuImg.PostedFile.FileName); new_filename = Guid.NewGuid().ToString() + Path.GetExtension(original_filename); string new_filepath = Server.MapPath("~/Uploads/Products/" + new_filename); fuImg.PostedFile.SaveAs(new_filepath); ViewState["NewImg"] = new_filename; } using (MashadCarpetEntities db = new MashadCarpetEntities()) { ProductColors p = new ProductColors(); p.ProductColorID = Guid.NewGuid(); p.IsDelete = false; p.ProductImage = new_filename; p.fk_ColorID = int.Parse(ddlColors.SelectedValue); p.fk_ProductID = ProductID; db.ProductColors.Add(p); db.SaveChanges(); } }
public async Task <int> AddProductColor(ProductColors productColor) { await _db.ProductColors.AddAsync(productColor); await _db.SaveChangesAsync(); return(productColor.ProductColorsId); }
public void rptRelatedProductsBind() { if (Request.QueryString["ColorID"] != null) { Guid ProductColorID = new Guid(Request.QueryString["ColorID"].ToString()); using (MashadCarpetEntities db = new MashadCarpetEntities()) { ProductColors n = db.ProductColors.Find(ProductColorID); Products o = db.Products.Find(n.fk_ProductID); if (!IdentifyCulture.cultureName().Contains("fa")) { var m = (from u in db.ProductColors join aa in db.Products on u.fk_ProductID equals aa.ProductID join aaa in db.ProductGroup on aa.fk_ProductGroupID equals aaa.ProductGroupID where u.fk_ProductID != n.fk_ProductID && aa.fk_ProductGroupID == o.fk_ProductGroupID && aa.IsDelete == false && aaa.IsDelete == false && u.IsDelete == false && aa.IsAlienCulture == true && aa.IsActive == true && u.ProductImage != null select new { u.ProductColorID, u.ProductImage, aa.ProductTitle, aaa.ProductGroupName, aa.ProductName }).ToList(); rptRelatedProducts.DataSource = m; rptRelatedProducts.DataBind(); } else { var m = (from u in db.ProductColors join aa in db.Products on u.fk_ProductID equals aa.ProductID join aaa in db.ProductGroup on aa.fk_ProductGroupID equals aaa.ProductGroupID where u.fk_ProductID != n.fk_ProductID && aa.fk_ProductGroupID == o.fk_ProductGroupID && aa.IsDelete == false && aaa.IsDelete == false && u.IsDelete == false && aa.IsAlienCulture != true && aa.IsActive == true && u.ProductImage != null select new { u.ProductColorID, u.ProductImage, aa.ProductTitle, aaa.ProductGroupName, aa.ProductName }).ToList(); rptRelatedProducts.DataSource = m; rptRelatedProducts.DataBind(); } } } }
public async Task <int> UpdateProductColorsAsync(ProductColors productColor) { var CheckExist = await _dataContext.ProductColors.Where(x => x.Id != productColor.Id) .SingleOrDefaultAsync(x => x.ArabicName == productColor.ArabicName || x.EnglishName == productColor.EnglishName); if (CheckExist != null) { return(-1); } _dataContext.ProductColors.Update(productColor); var Updated = await _dataContext.SaveChangesAsync(); return(Updated); }
public async Task <int> CreateProductColorsAsync(ProductColors productColor) { var CheckExist = await _dataContext.ProductColors .SingleOrDefaultAsync(x => x.ArabicName == productColor.ArabicName || x.EnglishName == productColor.EnglishName || x.HexCode == productColor.HexCode); if (CheckExist != null) { return(-1); } await _dataContext.ProductColors.AddAsync(productColor); var created = await _dataContext.SaveChangesAsync(); return(created); }
public ActionResult SaveColor(int id, string ad, string code) { using (MainContext db = new MainContext()) { ProductColors pinfo = new ProductColors(); pinfo.Adi = ad; pinfo.RenkKodu = code; pinfo.ProductId = id; //pinfo.ProductId = Convert.ToInt32(prid); db.ProductColors.Add(pinfo); db.SaveChanges(); ViewBag.PrId = id; ViewBag.Colors = db.ProductColors.Where(x => x.ProductId == id).ToList(); return(PartialView("~/Areas/Admin/Views/Product/_colorss.cshtml", ViewBag.Colors)); } }
protected void ddlColors_OnSelectedIndexChanged(object sender, EventArgs e) { int colorId = Convert.ToInt32(ddlColors.SelectedValue); Guid productId = new Guid(ddlProducts.SelectedValue); using (MashadCarpetEntities db = new MashadCarpetEntities()) { ProductColors productColors = db.ProductColors.Where(current => current.fk_ColorID == colorId && current.fk_ProductID == productId && current.IsDelete == false).FirstOrDefault(); List <ProductColorSizes> productColorSizes = db.ProductColorSizes.Where(current => current.fk_ProductColorID == productColors.ProductColorID && current.IsDelete == false).ToList(); ddlSize.Items.Clear(); ddlSize.Items.Add(new ListItem("سایز ", "-1")); foreach (var i in productColorSizes) { ddlSize.Items.Add(new ListItem(i.SIzes.SizeTitle.ToString(), i.SIzes.SizeID.ToString())); } } }
public PublishGoods(DataRow dr) { Url = Util.Get <string>(dr, "产品地址"); GoodsSn = Util.Get <string>(dr, "款号"); SalePrice = Util.Get <Double>(dr, "售价"); Stock = Util.Get <int>(dr, "库存"); string suk; if ((suk = Util.Get <string>(dr, "SKU")) != null) { ProductColors = JsonConvert.DeserializeObject <List <ProductColor> >(suk); //如果用户填了售价才更新价格,没有填就用导出的默认值。 if (SalePrice > 0) { foreach (var size in ProductColors.SelectMany(color => color.SizeList)) { size.MySalePrice = SalePrice; } } } IsSoldOut = Util.Get <bool>(dr, "售完"); }
public void UpdateWithExcell(string FileName) { ExcelPackage package = new ExcelPackage(FileUpload1.FileContent); DataTable datasource = package.ToDataTable(); // List<string> newproList = new List<string>(); foreach (DataRow dr in datasource.Rows) { using (MashadCarpetEntities db = new MashadCarpetEntities()) { string ProductName = dr["FldNaghshe"].ToString(); string colortoret = dr["FldZamine"].ToString(); string sizetoret = ReturnOrginalSize(dr["FldSiz"].ToString()); string tarakom = (dr["FldTarakom"].ToString()); string rang = (dr["FldTedadRang"].ToString()); string shane = (dr["FldShane"].ToString()); int fldNaghshei = 0; String[] elements = Regex.Split(dr["FldNaghshe"].ToString(), @"\D+"); foreach (var element in elements) { if (!string.IsNullOrEmpty(element)) { fldNaghshei = int.Parse(element); } } if (returnOrginalshane(shane) != null) { shane = returnOrginalshane(shane); } string systemname = shane + "-" + rang + "-" + tarakom; var n = (from a in db.ProductGroup where a.ProductGroupName == systemname && a.IsDelete == false /*&& a.IsAlienCulture==true*/ select a).FirstOrDefault(); if (n == null) { systemname = shane + "-" + rang + "-" + tarakom; } var o = (from a in db.Products where a.ProductName == ProductName && a.IsDelete == false && a.fk_ProductGroupID == n.ProductGroupID && a.IsAlienCulture == true select a).FirstOrDefault(); if (o == null) { //Insert into All 3 Tables //////////////////////////////// Products et = new Products(); et.ProductID = Guid.NewGuid(); et.fk_ProductGroupID = n.ProductGroupID; et.IsDelete = false; et.ProductTitle = dr["FldNaghshe"].ToString(); et.ProductName = dr["FldNaghshe"].ToString(); et.ProductUniqeCode = fldNaghshei; et.DesignNo = fldNaghshei; et.Frame = Convert.ToInt32(dr["FldTedadRang"].ToString()); et.Reeds = shane; et.Shots = tarakom; et.IsActive = true; et.IsAlienCulture = true; et.EN_ProductTitle = ProductName; et.Rus_ProductTitle = ProductName; et.China_ProductTitle = ProductName; db.Products.Add(et); ProductColors pcEnter = new ProductColors(); pcEnter.ProductColorID = Guid.NewGuid(); pcEnter.fk_ProductID = et.ProductID; pcEnter.IsDelete = false; pcEnter.fk_ColorID = returnColorID(colortoret); db.ProductColors.Add(pcEnter); ProductColorSizes pcsEnter = new ProductColorSizes(); pcsEnter.ProductColorSizeID = Guid.NewGuid(); pcsEnter.fk_ProductColorID = pcEnter.ProductColorID; pcsEnter.ProductPrice = Convert.ToDecimal(dr["FldGheymat"].ToString()); pcsEnter.Stock = Convert.ToInt32(dr["FldMojoodi"].ToString()); pcsEnter.fk_SizeID = returnSizeID(sizetoret); pcsEnter.IsDelete = false; pcsEnter.IsAvailable = true; pcsEnter.FileName = FileName; db.ProductColorSizes.Add(pcsEnter); db.SaveChanges(); } else { string productName = dr["FldNaghshe"].ToString(); var ProductID = o.ProductID; o.IsActive = true; // string colortoret = dr["FldZamine"].ToString(); //string sizetoret = returnOrginalSize(dr["FldSiz"].ToString()); int colorid = returnColorID(colortoret); int sizeid = returnSizeID(sizetoret); var ProductColorID = (from a in db.ProductColors where a.fk_ColorID == colorid && a.fk_ProductID == ProductID && a.IsDelete == false select new { a.ProductColorID }).FirstOrDefault(); ////////////////////////////////////// if (ProductColorID == null) { ProductColors pcEnter = new ProductColors(); pcEnter.ProductColorID = Guid.NewGuid(); pcEnter.fk_ProductID = ProductID; pcEnter.IsDelete = false; pcEnter.fk_ColorID = returnColorID(colortoret); db.ProductColors.Add(pcEnter); ProductColorSizes pcsEnter = new ProductColorSizes(); pcsEnter.ProductColorSizeID = Guid.NewGuid(); pcsEnter.fk_ProductColorID = pcEnter.ProductColorID; pcsEnter.ProductPrice = Convert.ToDecimal(dr["FldGheymat"].ToString()); pcsEnter.Stock = Convert.ToInt32(dr["FldMojoodi"].ToString()); pcsEnter.fk_SizeID = returnSizeID(sizetoret); pcsEnter.IsDelete = false; pcsEnter.FileName = FileName; pcsEnter.IsAvailable = true; db.ProductColorSizes.Add(pcsEnter); db.SaveChanges(); } else { var pcs = (from a in db.ProductColorSizes where a.fk_ProductColorID == ProductColorID.ProductColorID && a.fk_SizeID == sizeid && a.IsDelete == false select a).FirstOrDefault(); if (pcs == null) { ProductColorSizes pcsEnter = new ProductColorSizes(); pcsEnter.ProductColorSizeID = Guid.NewGuid(); pcsEnter.fk_ProductColorID = ProductColorID.ProductColorID; pcsEnter.ProductPrice = Convert.ToDecimal(dr["FldGheymat"].ToString()); pcsEnter.Stock = Convert.ToInt32(dr["FldMojoodi"].ToString()); pcsEnter.fk_SizeID = returnSizeID(sizetoret); pcsEnter.IsDelete = false; pcsEnter.FileName = FileName; pcsEnter.IsAvailable = true; db.ProductColorSizes.Add(pcsEnter); db.SaveChanges(); } else { pcs.Stock = Convert.ToInt32(dr["FldMojoodi"].ToString()); pcs.ProductPrice = Convert.ToDecimal(dr["FldGheymat"].ToString()); pcs.FileName = FileName; pcs.IsAvailable = true; db.SaveChanges(); } } } } } }
public async Task <IActionResult> EditPost(ProColors color) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { ViewBag.Color = _context.Colors; ViewBag.Size = _context.Sizes; ModelState.AddModelError("", "Xaiş olunur düzgün doldurun."); return(View(color)); } Products newProduct = await _context.Products.FindAsync(color.Id); Brands brand = await _context.Brands.FindAsync(newProduct.BrandsId); if (newProduct == null) { return(View("Error")); } if (color.AllPhotos != null) { IEnumerable <ProductPhoto> myPhoto = newProduct.Photos.Where(b => b.ProductsId == newProduct.Id); foreach (var photo in myPhoto) { string computerPhoto = Path.Combine(_env.WebRootPath, "img", photo.PhotoURL); if (System.IO.File.Exists(computerPhoto)) { System.IO.File.Delete(computerPhoto); } _context.RemoveRange(myPhoto); } bool isMain = true; foreach (var p in color.AllPhotos) { if (p != null) { if (p.ContentType.Contains("image/")) { string filename = await p.SaveAsync(_env.WebRootPath); ProductPhoto img = new ProductPhoto() { ProductsId = newProduct.Id, PhotoURL = filename }; if (isMain == true) { img.IsMain = true; } isMain = false; await _context.ProductPhoto.AddAsync(img); } } } } newProduct.Name = color.Name; newProduct.Info = color.Info; newProduct.Price = color.Price; IEnumerable <ProductColors> oldColors = _context.ProductColors.Where(p => p.ProductsId == newProduct.Id); IEnumerable <ProductSizes> oldSizes = _context.ProductSizes.Where(p => p.ProductsId == newProduct.Id); if (color.ColorsId != null) { _context.ProductColors.RemoveRange(oldColors); foreach (var c in color.ColorsId) { ProductColors proColors = new ProductColors() { ProductsId = newProduct.Id, ColorId = c }; await _context.ProductColors.AddAsync(proColors); } } if (color.SizesId != null) { _context.ProductSizes.RemoveRange(oldSizes); foreach (var s in color.SizesId) { ProductSizes proSize = new ProductSizes() { ProductsId = newProduct.Id, SizesId = s }; await _context.ProductSizes.AddAsync(proSize); } } await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = brand.Id })); }
public async Task <IActionResult> Create(ProColors colors) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (!User.IsInRole("Admin")) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { ViewBag.Active = "Home"; ViewBag.Color = _context.Colors; ViewBag.Brand = _context.Brands.Where(b => b.Id == colors.BrandsId); ViewBag.Size = _context.Sizes; return(View(colors)); } if (colors.AllPhotos == null) { ViewBag.Active = "Home"; ViewBag.Color = _context.Colors; ViewBag.Size = _context.Sizes; ViewBag.Brand = _context.Brands.Where(b => b.Id == colors.BrandsId); ModelState.AddModelError("AllPhotos", "Xahiş olunur şəkil əlavə edin."); return(View(colors)); } Products myProduct = new Products() { Name = colors.Name, Info = colors.Info, Price = colors.Price, BrandsId = colors.BrandsId }; await _context.Products.AddAsync(myProduct); bool isMain = true; foreach (var p in colors.AllPhotos) { if (p != null) { if (p.ContentType.Contains("image/")) { string filename = await p.SaveAsync(_env.WebRootPath); ProductPhoto img = new ProductPhoto() { ProductsId = myProduct.Id, PhotoURL = filename }; if (isMain == true) { img.IsMain = true; } isMain = false; await _context.ProductPhoto.AddAsync(img); } } } foreach (var c in colors.ColorsId) { ProductColors proColors = new ProductColors() { ProductsId = myProduct.Id, ColorId = c }; await _context.ProductColors.AddAsync(proColors); } foreach (var s in colors.SizesId) { ProductSizes proSize = new ProductSizes() { ProductsId = myProduct.Id, SizesId = s }; await _context.ProductSizes.AddAsync(proSize); } Brands brand = await _context.Brands.FindAsync(myProduct.BrandsId); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = brand.Id })); }
public async Task UpdateProductColor(ProductColors productColor) { _db.ProductColors.Update(productColor); await _db.SaveChangesAsync(); }