public ActionResult Create() { var model = new ContactInforViewModel(); //Add locales to model AddLocales(_languageService, model.Locales); return(View(model)); }
public ActionResult Create(ContactInforViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { var messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors) .Select(v => v.ErrorMessage + " " + v.Exception)); ModelState.AddModelError("", messages); return(View(model)); } var modelMap = Mapper.Map <ContactInforViewModel, ContactInformation>(model); _contactInfoService.Create(modelMap); //Update Localized foreach (var localized in model.Locales) { _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Title, localized.Title, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Address, localized.Address, localized.LanguageId); } Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.ContactInformation))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception exception1) { var exception = exception1; LogText.Log(string.Concat("MailSetting.Create: ", exception.Message)); return(View(model)); } return(action); }