public virtual async Task <IActionResult> Edit(AffiliateModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAffiliates)) { return(AccessDeniedView()); } //try to get an affiliate with the specified id var affiliate = await _affiliateService.GetAffiliateByIdAsync(model.Id); if (affiliate == null || affiliate.Deleted) { return(RedirectToAction("List")); } if (ModelState.IsValid) { var address = await _addressService.GetAddressByIdAsync(affiliate.AddressId); address = model.Address.ToEntity(address); //some validation if (address.CountryId == 0) { address.CountryId = null; } if (address.StateProvinceId == 0) { address.StateProvinceId = null; } await _addressService.UpdateAddressAsync(address); affiliate = model.ToEntity(affiliate); //validate friendly URL name var friendlyUrlName = await _affiliateService.ValidateFriendlyUrlNameAsync(affiliate, model.FriendlyUrlName); affiliate.FriendlyUrlName = friendlyUrlName; affiliate.AddressId = address.Id; await _affiliateService.UpdateAffiliateAsync(affiliate); //activity log await _customerActivityService.InsertActivityAsync("EditAffiliate", string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditAffiliate"), affiliate.Id), affiliate); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Affiliates.Updated")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = affiliate.Id })); } //prepare model model = await _affiliateModelFactory.PrepareAffiliateModelAsync(model, affiliate, true); //if we got this far, something failed, redisplay form return(View(model)); }