Ejemplo n.º 1
0
        public ActionResult Add(ContactInfoViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_iContactInfoService.Create(viewModel) > 0)
                    {
                        InformLog("Data saved successfully.", "Contact saved.");
                        return(Json(new { msg = "Data saved successfully.", status = MessageType.success.ToString() }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { msg = "Data could not saved.", status = MessageType.notice.ToString() }, JsonRequestBehavior.AllowGet));
                    }
                }

                return(Json(new { msg = ExceptionHelper.ModelStateErrorFormat(ModelState), status = MessageType.notice.ToString() }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { msg = ExceptionHelper.ExceptionMessageFormat(ex, log: true), status = MessageType.error.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Create(ContactInformationViewModel 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 <ContactInformationViewModel, 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;
                ExtentionUtils.Log(string.Concat("MailSetting.Create: ", exception.Message));
                return(View(model));
            }
            return(action);
        }