public async Task <ApplicationResult <BrandDto> > Update(UpdateBrandViewModel model) { try { var getExistBrand = await _context.Brands.FindAsync(model.Id); if (getExistBrand == null) { return(new ApplicationResult <BrandDto> { Result = new BrandDto(), Succeeded = false, ErrorMessage = "Böyle bir Marka bulunamadı!" }); } var modifierUser = await _userManager.FindByIdAsync(model.CreatedById); getExistBrand.ModifiedBy = modifierUser.UserName; _mapper.Map(model, getExistBrand); _context.Update(getExistBrand); await _context.SaveChangesAsync(); return(await Get(getExistBrand.Id)); } catch (Exception e) { return(new ApplicationResult <BrandDto> { Result = new BrandDto(), Succeeded = false, ErrorMessage = e.Message }); } }
public async Task <IActionResult> Edit(Guid id) { var getService = await _brandService.Get(id); var subCategoryList = await _subCategoryService.GetAll(); ViewBag.subCategoryDDL = subCategoryList.Result.Select(x => new SelectListItem { Selected = false, Text = x.SubCategoryName, Value = x.Id.ToString() }).ToList(); UpdateBrandViewModel model = new UpdateBrandViewModel() { Id = getService.Result.Id, CreatedById = getService.Result.CreatedById, ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value, BrandName = getService.Result.BrandName, BrandUrlName = getService.Result.BrandUrlName, SubCategoryId = getService.Result.SubCategoryId }; return(View(model)); }
public async Task <CommandResult <bool> > UpdateBrand([FromBody] UpdateBrandViewModel viewModel) { var updateBrandModel = _mapper.Map <WebSiteBrandModel>(viewModel); var result = await _brandManager.UpdateBrand(updateBrandModel); if (result.IsSucceeded) { this.ConfirmFileAdded(updateBrandModel.ImageFile); } return(result); }
public async Task <ActionResult <UpdateBrandViewModel> > Update(int?id) { if (id == null) { return(NotFound()); } UpdateBrandViewModel existBrand = _iMapper.Map <UpdateBrandViewModel> (await _iBrandManager.GetById(id)); if (existBrand == null) { return(NotFound()); } return(View(existBrand)); }
public async Task <IActionResult> Update(UpdateBrandViewModel updateBrandViewModel) { if (ModelState.IsValid) { Brand updateBrand = _iMapper.Map <Brand>(updateBrandViewModel); bool isAdd = await _iBrandManager.Update(updateBrand); if (isAdd) { return(RedirectToAction("Index")); } else { ViewBag.ErrorMessage = "Failed to Update Brand"; } } return(View(updateBrandViewModel)); }
public async Task <IActionResult> Edit(Guid id, UpdateBrandViewModel model) { //Hata olursa geri dönecek model var errorReturnModel = model; if (ModelState.IsValid) { if (id != model.Id) { ModelState.AddModelError(string.Empty, "Bir hata oluştu!"); } else { var getService = await _brandService.Get(id); model.CreatedById = getService.Result.CreatedById; model.Id = getService.Result.Id; model.ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value; var updateService = await _brandService.Update(model); if (updateService.Succeeded) { return(RedirectToAction("Details", new { id })); } ModelState.AddModelError(string.Empty, updateService.ErrorMessage); } } var subCategoryList = await _subCategoryService.GetAll(); ViewBag.subCategoryDDL = subCategoryList.Result.Select(x => new SelectListItem { Selected = false, Text = x.SubCategoryName, Value = x.Id.ToString() }).ToList(); return(View(errorReturnModel)); }