/// <summary> /// 新增 /// </summary> /// <param name="model"></param> /// <returns></returns> public IActionResult Add([FromBody] GoodsBrand model) { try { if (_goodsBrandRepository.Count(e => e.EnBrandName == model.EnBrandName && e.IsDel == 0) > 0) { return(JsonError("品牌英文名重复")); } if (_goodsBrandRepository.Count(e => e.ChsBrandName == model.ChsBrandName && e.IsDel == 0) > 0) { return(JsonError("品牌中文名重复")); } model.IsDel = 0; model.CreateTime = model.UpdateTime = DateTime.Now; model.CreateBy = model.UpdateBy = CurrentUser.Id; _goodsBrandRepository.Add(model); return(JsonOk("")); } catch (Exception ex) { return(JsonError(ex.Message)); } }
/// <summary> /// 修改(删除) /// </summary> /// <param name="model"></param> /// <returns></returns> public IActionResult Modify([FromBody] GoodsBrand model) { try { if (model.IsDel != 1 && _goodsBrandRepository.Count(e => e.Id != model.Id && e.EnBrandName == model.EnBrandName && e.IsDel == 0) > 0) { return(JsonError("品牌英文名重复")); } if (model.IsDel != 1 && _goodsBrandRepository.Count(e => e.Id != model.Id && e.ChsBrandName == model.ChsBrandName && e.IsDel == 0) > 0) { return(JsonError("品牌中文名重复")); } var oldModel = _goodsBrandRepository.GetSingle(model.Id); oldModel.ChsBrandName = model.ChsBrandName; oldModel.EnBrandName = model.EnBrandName; oldModel.IsDel = model.IsDel; oldModel.UpdateBy = CurrentUser.Id; oldModel.UpdateTime = DateTime.Now; _goodsBrandRepository.Update(oldModel); return(JsonOk("")); } catch (Exception ex) { return(JsonError(ex.Message)); } }
public ActionResult EditOnPost(GoodsBrand postGoodsBrand) { var goodsBrand = _currencyService.GetSingleById <GoodsBrand>(postGoodsBrand.Id); if (goodsBrand == null) { _currencyService.Create(postGoodsBrand); } else { _currencyService.Update(postGoodsBrand); } //处理主图图片关联 _storageFileService.ReplaceFile(postGoodsBrand.Id, MallModule.Key, MallModule.DisplayName, postGoodsBrand.Logo.ToGuid(), Logo); return(Json(new DataJsonResult())); }
public string AddGoodBrand(string brandName) { var loginUser = (UserInfo)Session["LoginUser"]; GoodsBrand brand = new GoodsBrand(); brand.CreateUserId = loginUser.UserId; brand.CreateUserName = loginUser.UserName; brand.Id = Guid.NewGuid(); brand.BrandName = brandName; brand.IsDelete = false; brand.Country = string.Empty; brand.Country = "中国"; var res = _manager.AddGoodsBrand(brand); return(Utils.SerializeObject(res)); }
public ActionResult Edit(Guid?id = null) { GoodsBrand goodsBrand = null; if (id != null && id != Guid.Empty) { goodsBrand = _currencyService.GetSingleById <GoodsBrand>(id); if (goodsBrand != null) { } } if (goodsBrand == null) { goodsBrand = new GoodsBrand { Id = KeyGenerator.GetGuidKey() }; } return(View(goodsBrand)); }
//更新信息 public static GoodsInfo GoodsInfoUpload(GoodsInfo goodsInfo, GoodsBrand goodsBrand, List <GoodsKind> goodsKinds, List <GoodsTag> goodsTags , GoodsPhoto goodsPhoto, GoodsDesc goodsDesc, List <GoodsSpecFull> goodsSpecsFull, GoodsCounter goodsCounter, out AlertMessage alertMessage) { //权限检查 if (!AUTH.PermissionCheck(ModuleInfo, ActionInfos.Where(i => i.Name == (goodsInfo.ID == 0 ? "Create" : "Modify")).FirstOrDefault(), out string Message)) { alertMessage = new AlertMessage { Message = Message, Type = AlertType.warning }; return(null); } //表单检查 if (string.IsNullOrWhiteSpace(goodsInfo.Name)) { alertMessage = new AlertMessage { Message = "商品代码不能为空。", Type = AlertType.warning }; return(null); } if (string.IsNullOrWhiteSpace(goodsInfo.Title)) { alertMessage = new AlertMessage { Message = "商品名称不能为空。", Type = AlertType.warning }; return(null); } using (var EF = new EF()) { //修改是否存在?商品代码唯一? GoodsInfo goods_exist = null; GoodsInfo goods_name_exist = null; if (goodsInfo.ID == 0) { goods_name_exist = EF.GoodsInfos.Where(i => i.Name == goodsInfo.Name).FirstOrDefault(); } else { goods_exist = EF.GoodsInfos.Where(i => i.ID == goodsInfo.ID).FirstOrDefault(); if (goods_exist == null) { alertMessage = new AlertMessage { Message = string.Format("商品编号[{0}]不存在。", goodsInfo.ID), Type = AlertType.warning }; return(null); } goods_name_exist = EF.GoodsInfos.Where(i => i.ID != goodsInfo.ID && i.Name == goodsInfo.Name).FirstOrDefault(); } if (goods_name_exist != null && goods_name_exist.ID > 0) { alertMessage = new AlertMessage { Message = string.Format("商品代码[{0}]已被ID[{1}]使用。", goodsInfo.Name, goods_name_exist.ID), Type = AlertType.warning }; return(null); } //数据保存 using (TransactionScope TS = new TransactionScope()) { if (goodsInfo.ID == 0) { goods_exist = EF.GoodsInfos.Add(new GoodsInfo { Enabled = true, StateID = (int)GoodsState.架, }); } goods_exist.Name = goodsInfo.Name; goods_exist.Title = goodsInfo.Title; EF.SaveChanges(); //品牌 var brand_exist = EF.GoodsBrands.Where(i => i.GoodsID == goods_exist.ID).FirstOrDefault(); if (brand_exist == null) { if (goodsBrand != null) { EF.GoodsBrands.Add(brand_exist = new GoodsBrand { GoodsID = goods_exist.ID, BrandID = goodsBrand.BrandID, }); } } else { if (goodsBrand == null) { EF.GoodsBrands.Remove(brand_exist); } else { brand_exist.BrandID = goodsBrand.BrandID; } } //品类 var kinds_exist = EF.GoodsKinds.Where(i => i.GoodsID == goods_exist.ID); foreach (var kind_exist in kinds_exist) { var exist_find = false; foreach (var goodsKind in goodsKinds) { if (goodsKind.KindLevel == kind_exist.KindLevel && goodsKind.KindID == kind_exist.KindID) { exist_find = true; goodsKinds.Remove(goodsKind); break; } } if (!exist_find) { EF.GoodsKinds.Remove(kind_exist); } } foreach (var goodsKind in goodsKinds) { goodsKinds.ForEach(i => i.GoodsID = goods_exist.ID); EF.GoodsKinds.Add(new GoodsKind { GoodsID = goods_exist.ID, KindLevel = goodsKind.KindLevel, KindID = goodsKind.KindID, }); } //标签 var tags_exist = EF.GoodsTags.Where(i => i.GoodsID == goods_exist.ID).ToList(); if (tags_exist != null) { EF.GoodsTags.RemoveRange(tags_exist); } if (goodsTags != null) { goodsTags.ForEach(i => i.GoodsID = goods_exist.ID); EF.GoodsTags.AddRange(goodsTags); } //图文 var photo_exist = EF.GoodsPhotos.Where(i => i.GoodsID == goods_exist.ID).FirstOrDefault(); if (photo_exist == null) { EF.GoodsPhotos.Add(photo_exist = new GoodsPhoto { GoodsID = goods_exist.ID, }); } photo_exist.FileIDs = goodsPhoto.FileIDs; var desc_exist = EF.GoodsDescs.Where(i => i.GoodsID == goods_exist.ID).FirstOrDefault(); if (desc_exist == null) { EF.GoodsDescs.Add(desc_exist = new GoodsDesc { GoodsID = goods_exist.ID, }); } desc_exist.Description = goodsDesc.Description; //规格 var specs_exist = EF.GoodsSpecs.Where(i => i.GoodsID == goods_exist.ID).ToList(); if (specs_exist != null) { specs_exist.ForEach(i => i.Enabled = false); EF.SaveChanges(); } foreach (var goodsSpecFill in goodsSpecsFull) { var spec_exist = EF.GoodsSpecs.Where(i => i.GoodsID == goods_exist.ID && i.SpecValueIDs == goodsSpecFill.SpecValueIDs).FirstOrDefault(); if (spec_exist == null) { EF.GoodsSpecs.Add(spec_exist = new GoodsSpec { GoodsID = goods_exist.ID, SpecValueIDs = goodsSpecFill.SpecValueIDs, }); } spec_exist.SpecValues = goodsSpecFill.SpecValues; spec_exist.Enabled = goodsSpecFill.Enabled; EF.SaveChanges(); var specCounter = EF.GoodsCounter.Where(i => i.GoodsID == goods_exist.ID && i.GoodsSpecID == spec_exist.ID).FirstOrDefault(); if (specCounter == null) { EF.GoodsCounter.Add(specCounter = new GoodsCounter { GoodsID = goods_exist.ID, GoodsSpecID = spec_exist.ID, }); } specCounter.SKU = goodsSpecFill.SKU; specCounter.UPC = goodsSpecFill.UPC; specCounter.EAN = goodsSpecFill.EAN; specCounter.JAN = goodsSpecFill.JAN; specCounter.ISBN = goodsSpecFill.ISBN; specCounter.Price = goodsSpecFill.Price ?? 0; specCounter.Quantity = goodsSpecFill.Quantity ?? 0; } //柜台 var counter_exist = EF.GoodsCounter.Where(i => i.GoodsSpecID == 0 && i.GoodsID == goods_exist.ID).FirstOrDefault(); if (counter_exist == null) { EF.GoodsCounter.Add(counter_exist = new GoodsCounter { GoodsSpecID = 0, }); } counter_exist.GoodsID = goods_exist.ID; counter_exist.SKU = goodsCounter.SKU; counter_exist.UPC = goodsCounter.UPC; counter_exist.EAN = goodsCounter.EAN; counter_exist.JAN = goodsCounter.JAN; counter_exist.ISBN = goodsCounter.ISBN; counter_exist.Price = goodsCounter.Price; counter_exist.Quantity = goodsCounter.Quantity; //保存 EF.SaveChanges(); TS.Complete(); } //更新完成 alertMessage = null; return(goods_exist); } }
public bool AddGoodsBrand(GoodsBrand brand) { _context.GoodsBrands.Add(brand); return(_context.SaveChanges() > 0); }
//信息表单保存按钮 public void InfoFormSubmit_Click(object sender, EventArgs e) { //品名 var goodsInfo = new Ziri.MDL.GoodsInfo { ID = long.Parse(hidInfoFormGoodsID.Value), Name = inpInfoFormGoodsName.Text, Title = inpInfoFormGoodsTitle.Text, }; //品牌 GoodsBrand goodsBrand = null; if (!string.IsNullOrWhiteSpace(hidInfoFormBrandID.Value)) { goodsBrand = new GoodsBrand { BrandID = long.Parse(hidInfoFormBrandID.Value), }; } //品类 List <GoodsKind> goodsKinds = new List <GoodsKind>(); long kindRootID = long.Parse(drpInfoFormKindRoot.SelectedValue); long kindL1ID = 0; try { kindL1ID = long.Parse(drpInfoFormKindL1.SelectedValue); } catch { } if (kindRootID > 0) { goodsKinds.Add(new GoodsKind { KindLevel = 0, KindID = kindRootID }); } if (kindL1ID > 0) { goodsKinds.Add(new GoodsKind { KindLevel = 1, KindID = kindL1ID }); } //图文 var PhotoUploadInfos = JsonConvert.DeserializeObject <List <FileUploadInfo> >(hidInfoFormGoodsPhoto.Value); var goodsPhoto = new GoodsPhoto { FileIDs = string.Join(",", PhotoUploadInfos.Select(i => i.FileInfo.ID)), }; var goodsDesc = new GoodsDesc { Description = HttpUtility.UrlDecode(hidInfoFormGoodsDesc.Value) }; //规格 var goodsSpecsFull = new List <GoodsSpecFull>(); foreach (var specInfo in lvInfoFormSpec.Items) { var valueIDs = (HiddenField)specInfo.FindControl("hidValueIDs"); if (!string.IsNullOrWhiteSpace(valueIDs.Value)) { var inpSpecPrice = (TextBox)specInfo.FindControl("inpSpecPrice"); var inpSpecQty = (TextBox)specInfo.FindControl("inpSpecQty"); goodsSpecsFull.Add(new GoodsSpecFull { SpecValueIDs = valueIDs.Value, SpecValues = ((HiddenField)specInfo.FindControl("hidValues")).Value, Enabled = ((HtmlInputCheckBox)specInfo.FindControl("inpSpecEnabled")).Checked, SKU = ((TextBox)specInfo.FindControl("inpInfoFormSKU")).Text, UPC = ((TextBox)specInfo.FindControl("inpInfoFormUPC")).Text, EAN = ((TextBox)specInfo.FindControl("inpInfoFormEAN")).Text, JAN = ((TextBox)specInfo.FindControl("inpInfoFormJAN")).Text, ISBN = ((TextBox)specInfo.FindControl("inpInfoFormISBN")).Text, Price = string.IsNullOrWhiteSpace(inpSpecPrice.Text) ? 0 : decimal.Parse(inpSpecPrice.Text), Quantity = string.IsNullOrWhiteSpace(inpSpecQty.Text) ? 0 : decimal.Parse(inpSpecQty.Text), }); } } //单价 var goodsCounter = new GoodsCounter { SKU = inpInfoFormSKU.Text, UPC = inpInfoFormUPC.Text, EAN = inpInfoFormEAN.Text, JAN = inpInfoFormJAN.Text, ISBN = inpInfoFormISBN.Text, Price = decimal.Parse(inpInfoFormPrice.Text), Quantity = decimal.Parse(inpInfoFormQuantity.Text), }; //保存 goodsInfo = Ziri.BLL.ITEM.Goods.GoodsInfoUpload(goodsInfo, goodsBrand, goodsKinds, GetGoodsTags(), goodsPhoto, goodsDesc, goodsSpecsFull, goodsCounter, out AlertMessage alertMessage); if (alertMessage == null) { ListBind(); } Page.ClientScript.RegisterStartupScript(Page.GetType(), "InfoFormMessage", alertMessage == null ? string.Format("<script> swal('保存完成,商品编号[{0}]。', '', '{1}'); </script>", goodsInfo.ID, AlertType.success) : string.Format("<script> document.getElementById('btnListInfoFormModal').click(); swal('{0}', '', '{1}'); </script>", alertMessage.Message, alertMessage.Type)); }