public async Task <int> UpdateAsync(ProductPackageUpdateViewModel vm, IFormFile file) { var model = GetById(vm.Id); if (file != null) { if (vm.IndexPic != null) { try { var WebContent = _hostingEnvironment.WebRootPath; System.IO.File.Delete(WebContent + FilePath.productPackage.GetDescription()); } catch (Exception) { return(0); } } vm.IndexPic = await MFile.Save(file, FilePath.productPackage.GetDescription()); } else { vm.IndexPic = model.IndexPic; } Mapper.Map(vm, model); await DbContext.SaveChangesAsync(); return(model.Id); }
public async Task <IActionResult> Update(ProductPackageUpdateViewModel package , PackageFeatureInsertViewModel vm , List <int> groups , IFormFile file) { if (_productPackageGroupRepository.IsGroupChanged(package.Id, groups)) { await _productPackageDetailsRepostitory.RemoveProductsbyPackageId(package.Id); } // ویرایش پکیج var productId = await _productPackageRepostitory.UpdateAsync(package, file); await _productPackageGroupRepository.AddGroupRange(groups, package.Id); if (vm.Items != null || vm.Items.Count > 0) { await _packageUserAnswerRepository.UpdateAnswer(vm, UserId, package.Id); } TempData.AddResult(SweetAlertExtenstion.Ok()); // بازگشت به لیست محصولات return(Redirect(IndexUrlWithQueryString)); }