Пример #1
0
        public virtual ActionResult Save(ProfileTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var profileType = profileTypeService.Find(model.Id);

                if (profileType == null)
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
                }

                if (profileTypeService.Save(model.MapTo(profileType)))
                {
                    //save locale
                    var localeService        = ServiceLocator.Current.GetInstance <IProfileTypeLocaleService>();
                    ProfileTypeLocale locale = localeService.GetLocale(profileType.Id, model.SelectedCulture);
                    locale = model.MapLocaleTo(locale ?? new ProfileTypeLocale {
                        ProfileType = profileType
                    });

                    localeService.Save(locale);

                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(ProfilesMVC.ProfileType.Edit(model.Id)));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            return(View("Edit", model));
        }
Пример #2
0
        public virtual ActionResult New(ProfileTypeViewModel profileType)
        {
            if (ModelState.IsValid)
            {
                var newProfileType = profileType.MapTo(new ProfileType {
                    UserId = this.CorePrincipal() != null ? this.CorePrincipal().PrincipalId : (long?)null, CreateDate = DateTime.Now
                });
                if (profileTypeService.Save(newProfileType))
                {
                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(ProfilesMVC.ProfileType.Edit(newProfileType.Id)));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            return(View("New", profileType));
        }
        public virtual ActionResult New(ProfileTypeViewModel profileType)
        {
            if (ModelState.IsValid)
            {
                var newProfileType = profileType.MapTo(new ProfileType { UserId = this.CorePrincipal() != null ? this.CorePrincipal().PrincipalId : (long?)null, CreateDate = DateTime.Now });
                if (profileTypeService.Save(newProfileType))
                {
                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return RedirectToAction(ProfilesMVC.ProfileType.Edit(newProfileType.Id));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));

            }

            return View("New", profileType);
        }
        public virtual ActionResult Save(ProfileTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var profileType = profileTypeService.Find(model.Id);

                if (profileType == null)
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
                }

                if (profileTypeService.Save(model.MapTo(profileType)))
                {
                    //save locale
                    var localeService = ServiceLocator.Current.GetInstance<IProfileTypeLocaleService>();
                    ProfileTypeLocale locale = localeService.GetLocale(profileType.Id, model.SelectedCulture);
                    locale = model.MapLocaleTo(locale ?? new ProfileTypeLocale { ProfileType = profileType });

                    localeService.Save(locale);

                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return RedirectToAction(ProfilesMVC.ProfileType.Edit(model.Id));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            return View("Edit", model);
        }