public async Task <DbResponse> EditAsync(BrandEditModel model, IFormFile fileLogo, ICloudStorage cloudStorage) { try { if (_db.Brand.IsNull(model.BrandId)) { return(new DbResponse(false, "Data not found")); } if (string.IsNullOrEmpty(model.Name)) { return(new DbResponse(false, "Invalid Data")); } if (_db.Brand.IsExistName(model.Name, model.BrandId)) { return(new DbResponse(false, $"{model.Name} already Exist")); } model.LogoFileName = await cloudStorage.UpdateFileAsync(fileLogo, model.LogoFileName, "brand-logo"); _db.Brand.Edit(model); _db.SaveChanges(); return(new DbResponse(true, "Success")); } catch (Exception e) { return(new DbResponse(false, e.Message)); } }
public ActionResult Edit(int brandid = 0) { var model = new BrandEditModel(); if (brandid > 0) { var brand = BrandBLL.Instance.Brand_Get(brandid); if (brand != null) { model.BrandID = brand.BrandID; model.BrandType = brand.BrandType; model.ChineseName = brand.ChineseName; model.Description = brand.Description; model.EnglishName = brand.EnglishName; model.ImageBanner = brand.ImageBanner; model.ImageLogo = brand.ImageLogo; model.Keywords = brand.Keywords; model.MetaDescription = brand.MetaDescription; model.RegTrademark = brand.RegTrademark; model.Title = brand.Title; model.UnregTrademark = brand.UnregTrademark; } } return(View(model)); }
public async Task <IActionResult> UpdateBrand(BrandEditModel model, IFormFile fileLogo) { var response = await _brand.EditAsync(model, fileLogo, _cloudStorage); return(Json(response)); }
public ActionResult EditModel(BrandEditModel model) { model.Error = string.Empty; BrandInfo brand = null; if (model.BrandID > 0) { brand = BrandBLL.Instance.Brand_Get(model.BrandID); } if (brand == null) { brand = new BrandInfo(); } brand.ChineseName = model.ChineseName; if (string.IsNullOrWhiteSpace(brand.ChineseName)) { model.Error = "请输入品牌名称!"; return(View("Edit", model)); } if (model.BrandType < 0) { model.Error = "请选择品牌类别!"; return(View("Edit", model)); } //判断当前名称是否存在 if (brand.ChineseName != model.ChineseName) { var recordCount = 0; var list = BrandBLL.Instance.Brand_GetList(1, 1, "", string.Format("ChineseName='{0}'", brand.ChineseName), out recordCount); if (list.Count > 0) { model.Error = "该品牌名称已存在!"; return(View("Edit", model)); } } brand.BrandType = model.BrandType; brand.Description = model.Description; brand.PinyinName = JXUtil.PinyinUtil.ConvertToPinyin(model.ChineseName); brand.EnglishName = model.EnglishName; brand.Keywords = model.Keywords; brand.MetaDescription = model.MetaDescription; if (model.BrandID > 0) { BrandBLL.Instance.Brand_Update(brand); } else { brand.BrandID = BrandBLL.Instance.Brand_Insert(brand); } var img = Request.Files[0]; if (img != null && img.ContentLength > 0) { var result = ProductImage.Instance.BrandUpload(brand.BrandID + "_" + brand.PinyinName, 1, img); var path = JXAPI.JXSdk.Utils.JsonHelper.ConvertToObj <List <JXAPI.JXSdk.Request.ImagePathRequest> >(result.data.ToString()); brand.ImageLogo = path[0].ImagePath.TrimStart('/'); model.ImageLogo = brand.ImageLogo; BrandBLL.Instance.Brand_Update(brand); } model.BrandID = brand.BrandID; //return View("Edit", model); return(RedirectToAction("brandlist")); }