コード例 #1
0
        public ActionResult Show(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var user       = repository.GetById(id);

            if (!CurrentUser.CanManageAccount() && user.Id != CurrentUser.Id)
            {
                throw new NoAccessToPageException();
            }

            var model = new ShowUserModel()
            {
                Id          = user.Id,
                Login       = user.Login,
                DisplayName = user.DisplayName,
                Contacts    = user.UserContacts.ToList(),
                Role        = user.Roles.Any() ? user.Roles.First().Role.DisplayName : "нет"
            };

            var userSettingService = CurrentAccountDbContext.GetUserSettingService();

            model.SendMeNews = userSettingService.SendMeNews(user.Id);

            return(View(model));
        }
コード例 #2
0
        public ActionResult Index(TimelineInterval?interval)
        {
            var userSettingService = CurrentAccountDbContext.GetUserSettingService();
            var savedInterval      = (TimelineInterval?)userSettingService.ComponentHistoryInterval(CurrentUser.Id) ?? TimelineInterval.Hour;

            if (interval != null)
            {
                userSettingService.ComponentHistoryInterval(CurrentUser.Id, (int)interval.Value);
                DbContext.SaveChanges();
            }

            var model = new IndexModel()
            {
                Interval = interval ?? savedInterval
            };

            model.ToDate   = MvcApplication.GetServerDateTime();
            model.FromDate = TimelineHelper.IntervalToStartDate(model.ToDate, model.Interval);

            return(View(model));
        }
コード例 #3
0
        public ActionResult Index(
            ColorStatusSelectorValue color,
            Guid?componentTypeId = null,
            string search        = null,
            string save          = null)
        {
            if (save == "1")
            {
                var service = CurrentAccountDbContext.GetUserSettingService();
                service.ShowComponentsAsList(CurrentUser.Id, false);
                CurrentAccountDbContext.SaveChanges();
                return(RedirectToAction("Index", new { color = color.HasValue ? color : null, componentTypeId, search }));
            }

            var model = new ComponentsTreeModel()
            {
                ComponentTypeId = componentTypeId,
                Color           = color,
                Search          = search
            };

            return(View(model));
        }
コード例 #4
0
        public ActionResult Edit(EditUserModel model)
        {
            var userService = new UserService(DbContext);
            var user        = userService.GetById(CurrentUser.AccountId, model.Id);

            if (!CurrentUser.CanManageAccount() && user.Id != CurrentUser.Id)
            {
                throw new NoAccessToPageException();
            }

            model.Contacts = user.UserContacts.ToList();

            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(model.DisplayName))
                {
                    var modelState = new ModelStateHelper <EditUserModel>(ModelState);
                    modelState.AddErrorFor(x => x.DisplayName, "Значение не должно быть пустым");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                user.Login       = model.Login;
                user.DisplayName = model.DisplayName;
                user.Post        = model.Post;

                // обновим роль, если она поменялась
                if (CurrentUser.CanManageAccount())
                {
                    if (user.Roles.First().RoleId != model.RoleId)
                    {
                        foreach (var role in user.Roles.ToArray())
                        {
                            userService.RemoveUserRole(user, role, CurrentUser.AccountId);
                        }

                        if (model.RoleId.HasValue)
                        {
                            userService.AddUserRole(user, new UserRole()
                            {
                                RoleId = model.RoleId.Value
                            });
                        }
                    }
                }

                userService.UpdateUserLogin(user);

                var userSettingService = CurrentAccountDbContext.GetUserSettingService();
                userSettingService.SendMeNews(user.Id, model.SendMeNews);

                DbContext.SaveChanges();
            }
            catch (UserFriendlyException e)
            {
                ModelState.AddModelError("", e.Message);
                return(View(model));
            }

            return(RedirectToAction("Show", new { id = user.Id }));
        }