Ejemplo n.º 1
0
        public ActionResult Settings(UserSettingsModel model)
        {
            if (!ModelState.IsValid)
            {
                using (UsersRepository userRepository = new UsersRepository(CurrentUser.CompanyId))
                using (LanguagesRepository languagesRepository = new LanguagesRepository())
                {
                    User user = userRepository.GetEntity(CurrentUser.UserId);
                    model.NotificationsEmail = user.NotificationEmail;
                    ViewBag.LanguagesList = new SelectList(languagesRepository.GetList().ToList(), "Id", "Name", user.LanguageId);
                }

                return View(model);
            }

            using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId))
            {
                User user = usersRep.GetList().SingleOrDefault(x => x.Id == CurrentUser.UserId);
                user.LanguageId = model.LanguageId;
                user.NotificationEmail = String.IsNullOrEmpty(model.NotificationsEmail) ? null : model.NotificationsEmail;

                if (usersRep.Update(user) == null) return Error(Loc.Dic.error_database_error);
                CurrentUser.LanguageCode = user.Language.Code;
                CurrentUser.NotificationEmail = user.NotificationEmail;

                return RedirectToAction("index", "Home");
            }
        }
Ejemplo n.º 2
0
        public ActionResult Settings()
        {
            UserSettingsModel model = new UserSettingsModel();
            using (UsersRepository userRepository = new UsersRepository(CurrentUser.CompanyId))
            using (LanguagesRepository languagesRepository = new LanguagesRepository())
            {
                User user = userRepository.GetEntity(CurrentUser.UserId);
                model.NotificationsEmail = user.NotificationEmail;
                ViewBag.LanguagesList = new SelectList(languagesRepository.GetList().ToList(), "Id", "Name", user.LanguageId);
            }

            return View(model);
        }