public async Task <DbResponse> EditAsync(CatalogDisplayModel model, ICloudStorage cloudStorage, IFormFile image) { try { if (string.IsNullOrEmpty(model.CatalogName) && string.IsNullOrEmpty(model.SlugUrl)) { return(new DbResponse(false, "Invalid Data")); } if (_db.Catalog.IsExistName(model.CatalogName, model.CatalogId)) { return(new DbResponse(false, $"{model.CatalogName} already Exist")); } if (_db.Catalog.IsExistSlugUrl(model.SlugUrl, model.CatalogId)) { return(new DbResponse(false, $"{model.SlugUrl} SlugUrl already Exist")); } model.ImageFileName = await cloudStorage.UpdateFileAsync(image, model.ImageFileName, "catalog"); _db.Catalog.Edit(model); _db.SaveChanges(); return(new DbResponse(true, "Success")); } catch (Exception e) { return(new DbResponse(false, e.Message)); } }
public async Task <IActionResult> Update(CatalogDisplayModel model, IFormFile fileImage) { ViewBag.ParentCatalog = new SelectList(_catalog.ListDdl().Data, "value", "label"); var response = await _catalog.EditAsync(model, _cloudStorage, fileImage); if (!response.IsSuccess) { ModelState.AddModelError(response.FieldName, response.Message); } if (!ModelState.IsValid) { return(View(model)); } return(RedirectToAction("Index")); }