public async Task <ApplicationResult <SubCategoryDto> > Update(UpdateSubCategoryViewModel model) { try { var getExistSubCategory = await _context.SubCategories.FindAsync(model.Id); if (getExistSubCategory == null) { return(new ApplicationResult <SubCategoryDto> { Result = new SubCategoryDto(), Succeeded = false, ErrorMessage = "Böyle bir Kategori bulunamadı" }); } var modifierUser = await _userManager.FindByIdAsync(model.ModifiedById); getExistSubCategory.ModifiedBy = modifierUser.UserName; _mapper.Map(model, getExistSubCategory); _context.Update(getExistSubCategory); await _context.SaveChangesAsync(); return(await Get(getExistSubCategory.Id)); } catch (Exception e) { return(new ApplicationResult <SubCategoryDto> { Result = new SubCategoryDto(), Succeeded = false, ErrorMessage = e.Message }); } }
public async Task <IActionResult> Edit(Guid id) { var getService = await _subCategoryService.Get(id); var categoryList = await _categoryService.GetAll(); ViewBag.CategoryDDL = categoryList.Result.Select(x => new SelectListItem { Selected = false, Text = x.CategoryName, Value = x.Id.ToString() }).ToList(); UpdateSubCategoryViewModel model = new UpdateSubCategoryViewModel { Id = getService.Result.Id, CreatedById = getService.Result.CreatedById, ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value, SubCategoryName = getService.Result.SubCategoryName, SubCategoryUrlName = getService.Result.SubCategoryName, CategoryId = getService.Result.CategoryId }; return(View(model)); }
public async Task <ActionResult> Edit(UpdateSubCategoryViewModel subCategory) { if (ModelState.IsValid) { var currentSubCategory = await _subCategoryRepository.GetByIdAsync(subCategory.SubCategoryId); currentSubCategory.Name = subCategory.Name; currentSubCategory.Description = subCategory.Description; await _subCategoryRepository.Update(currentSubCategory); return(RedirectToAction("Details", "Category", new { Id = subCategory.CategoryId })); } return(View(subCategory)); }
public async Task <ActionResult> Edit(int subCategoryId) { var currentSubCategory = await _subCategoryRepository.GetByIdAsync(subCategoryId); var viewModel = new UpdateSubCategoryViewModel { SubCategoryId = currentSubCategory.Id, CategoryId = currentSubCategory.CategoryId, Name = currentSubCategory.Name, Description = currentSubCategory.Description }; return(View(viewModel)); }
public async Task <IActionResult> Edit(Guid id, UpdateSubCategoryViewModel 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 _subCategoryService.Get(id); model.CreatedById = getService.Result.CreatedById; model.Id = getService.Result.Id; model.ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value; var updateService = await _subCategoryService.Update(model); if (updateService.Succeeded) { return(RedirectToAction("Details", new { id })); } ModelState.AddModelError(string.Empty, updateService.ErrorMessage); } } var categoryList = await _categoryService.GetAll(); ViewBag.CategoryDDL = categoryList.Result.Select(x => new SelectListItem { Selected = false, Text = x.CategoryName, Value = x.Id.ToString() }).ToList(); return(View(errorReturnModel)); }