public IActionResult ValueCreatePopup(ContactAttributeValueModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } var contactAttribute = _contactAttributeService.GetContactAttributeById(model.ContactAttributeId); if (contactAttribute == null) { //No contact attribute found with the specified id return(RedirectToAction("List")); } if (contactAttribute.AttributeControlType == AttributeControlType.ColorSquares) { //ensure valid color is chosen/entered if (String.IsNullOrEmpty(model.ColorSquaresRgb)) { ModelState.AddModelError("", "Color is required"); } //TO DO //try //{ // //ensure color is valid (can be instanciated) // System.Drawing.ColorTranslator.FromHtml(model.ColorSquaresRgb); //} //catch (Exception exc) //{ // ModelState.AddModelError("", exc.Message); //} } if (ModelState.IsValid) { var cav = new ContactAttributeValue { ContactAttributeId = model.ContactAttributeId, Name = model.Name, ColorSquaresRgb = model.ColorSquaresRgb, IsPreSelected = model.IsPreSelected, DisplayOrder = model.DisplayOrder, }; cav.Locales = UpdateValueLocales(cav, model); contactAttribute.ContactAttributeValues.Add(cav); _contactAttributeService.UpdateContactAttribute(contactAttribute); ViewBag.RefreshPage = true; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
protected virtual List <LocalizedProperty> UpdateValueLocales(ContactAttributeValue contactAttributeValue, ContactAttributeValueModel model) { List <LocalizedProperty> localized = new List <LocalizedProperty>(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Name))) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name, }); } } return(localized); }
public virtual async Task <ContactAttributeValue> UpdateContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValue contactAttributeValue, ContactAttributeValueModel model) { contactAttributeValue = model.ToEntity(contactAttributeValue); await _contactAttributeService.UpdateContactAttribute(contactAttribute); return(contactAttributeValue); }
public virtual ContactAttributeValueModel PrepareContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValue contactAttributeValue) { var model = contactAttributeValue.ToModel(); model.DisplayColorSquaresRgb = contactAttribute.AttributeControlType == AttributeControlType.ColorSquares; return(model); }
public virtual ContactAttributeValue UpdateContactAttributeValueModel(ContactAttribute contactAttribute, ContactAttributeValue contactAttributeValue, ContactAttributeValueModel model) { contactAttributeValue = model.ToEntity(contactAttributeValue); _contactAttributeService.UpdateContactAttribute(contactAttribute); return(contactAttributeValue); }
public static ContactAttributeValue ToEntity(this ContactAttributeValueModel model, ContactAttributeValue destination) { return(model.MapTo(destination)); }
//contact attribute value public static ContactAttributeValueModel ToModel(this ContactAttributeValue entity) { return(entity.MapTo <ContactAttributeValue, ContactAttributeValueModel>()); }