コード例 #1
0
        public async Task <IActionResult> Edit(ContactInfoUpdateDto contactInfoUpdateDto)
        {
            if (ModelState.IsValid)
            {
                await _contactInfoService.Update(contactInfoUpdateDto, "Hasan Erdal");

                return(RedirectToAction("Index"));
            }
            return(View(contactInfoUpdateDto));
        }
コード例 #2
0
        public ActionResult Edit(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.Update(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.UpdateSuccess, 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);
        }