public virtual IActionResult ValueEditPopup(ContractAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) { return(AccessDeniedView()); } //try to get a customer attribute value with the specified id var contractAttributeValue = _contractAttributeService.GetContractAttributeValueById(model.Id); if (contractAttributeValue == null) { return(RedirectToAction("List")); } //try to get a customer attribute with the specified id var contractAttribute = _contractAttributeService.GetContractAttributeById(contractAttributeValue.ContractAttributeId); if (contractAttribute == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { contractAttributeValue = model.ToEntity(contractAttributeValue); _contractAttributeService.UpdateContractAttributeValue(contractAttributeValue); //activity log _customerActivityService.InsertActivity("EditContractAttributeValue", string.Format(_localizationService.GetResource("ActivityLog.EditContractAttributeValue"), contractAttributeValue.Id), contractAttributeValue); UpdateValueLocales(contractAttributeValue, model); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _contractAttributeModelFactory.PrepareContractAttributeValueModel(model, contractAttribute, contractAttributeValue, true); //if we got this far, something failed, redisplay form return(View(model)); }
public virtual ContractAttributeValueModel PrepareContractAttributeValueModel(ContractAttributeValueModel model, ContractAttribute contractAttribute, ContractAttributeValue contractAttributeValue, bool excludeProperties = false) { if (contractAttribute == null) { throw new ArgumentNullException(nameof(contractAttribute)); } Action <ContractAttributeValueLocalizedModel, int> localizedModelConfiguration = null; if (contractAttributeValue != null) { model = model ?? contractAttributeValue.ToModel <ContractAttributeValueModel>(); localizedModelConfiguration = (locale, languageId) => { locale.Name = _localizationService.GetLocalized(contractAttributeValue, entity => entity.Name, languageId, false, false); }; } model.ContractAttributeId = contractAttribute.Id; if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
protected virtual void UpdateValueLocales(ContractAttributeValue contractAttributeValue, ContractAttributeValueModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(contractAttributeValue, x => x.Name, localized.Name, localized.LanguageId); } }