Exemple #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));
        }
Exemple #2
0
        public ActionResult Show(Guid id, Guid componentId)
        {
            var storageContext         = CurrentAccountDbContext;
            var notificationRepository = storageContext.GetNotificationRepository();
            var notification           = notificationRepository.Find(id, componentId);

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

            var userRepository         = CurrentAccountDbContext.GetUserRepository();
            var user                   = userRepository.GetById(notification.UserId);
            var subscriptionRepository = CurrentAccountDbContext.GetSubscriptionRepository();
            var subscription           = notification.SubscriptionId.HasValue ? subscriptionRepository.GetById(notification.SubscriptionId.Value) : null;
            var model                  = new NotificationDetailsModel()
            {
                Id           = notification.Id,
                Channel      = notification.Type,
                CreationDate = notification.CreationDate,
                Event        = notification.Event,
                SendDate     = notification.SendDate,
                SendError    = notification.SendError,
                Status       = notification.Status,
                Subscription = subscription,
                User         = user,
                Address      = notification.Address
            };

            return(View(model));
        }
        public ActionResult QuickSetMobilePhone(QuickSetMobilePhoneModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            var userRepository = CurrentAccountDbContext.GetUserRepository();
            var user           = userRepository.GetById(CurrentUser.Id);

            userRepository.AddContactToUser(user.Id, UserContactType.MobilePhone, model.Phone, MvcApplication.GetServerDateTime());

            var client = GetDispatcherClient();

            var response = client.CreateSubscription(CurrentUser.AccountId, new CreateSubscriptionRequestData()
            {
                UserId    = CurrentUser.Id,
                Channel   = SubscriptionChannel.Sms,
                Object    = SubscriptionObject.Default,
                IsEnabled = true
            });

            response.Check();

            this.SetTempMessage(TempMessageType.Success, "Мобильный телефон успешно добавлен. Теперь вы будете получать уведомления по SMS!");

            return(Redirect(model.ReturnUrl ?? Url.Action("Start")));
        }
Exemple #4
0
        public ActionResult Index()
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var usersList  = repository.QueryAll().OrderBy(x => x.Login);

            return(View(usersList));
        }
        public ActionResult Start()
        {
            var userRepository = CurrentAccountDbContext.GetUserRepository();
            var user           = userRepository.GetById(CurrentUser.Id);
            var hasMobilePhone = user.UserContacts.Any(t => t.Type == UserContactType.MobilePhone && !string.IsNullOrEmpty(t.Value));

            var model = new StartModel()
            {
                HintSetMobilePhone = !hasMobilePhone && CurrentUser.CanEditPrivateData()
            };

            return(View(model));
        }
Exemple #6
0
        public ActionResult Delete(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var user       = repository.GetById(id);
            var model      = new DeleteConfirmationModel()
            {
                Id        = user.Id.ToString(),
                Title     = "Удаление пользователя",
                ModalMode = Request.IsAjaxRequest(),
                Message   = "Вы действительно хотите удалить этого пользователя?",
                ReturnUrl = Url.Action("Index")
            };

            return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model));
        }
Exemple #7
0
        public ActionResult DeleteContact(DeleteConfirmationModel model)
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var contact    = repository.GetContactById(Guid.Parse(model.Id));

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

            repository.DeleteContactById(contact.Id);

            if (model.ModalMode)
            {
                return(new EmptyResult());
            }

            return(Redirect(model.ReturnUrl));
        }
Exemple #8
0
        public ActionResult AddContact(Guid userId)
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var user       = repository.GetById(userId);

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

            var model = new UserContactModel()
            {
                ModalMode = Request.IsAjaxRequest(),
                ReturnUrl = Url.Action("Edit", new { id = userId.ToString() }),
                UserId    = user.Id
            };

            return(View(model));
        }
Exemple #9
0
        public ActionResult EditContact(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var contact    = repository.GetContactById(id);

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

            var model = new UserContactModel()
            {
                ModalMode = Request.IsAjaxRequest(),
                ReturnUrl = Url.Action("Edit", new { id = contact.UserId.ToString() }),
                Id        = id,
                UserId    = contact.UserId,
                Type      = contact.Type,
                Value     = contact.Value
            };

            return(View(model));
        }
Exemple #10
0
        public ActionResult DeleteContact(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUserRepository();
            var contact    = repository.GetContactById(id);

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

            var model = new DeleteConfirmationModel()
            {
                Id                 = id.ToString(),
                Title              = "Удаление контакта",
                ModalMode          = Request.IsAjaxRequest(),
                Message            = "Вы действительно хотите удалить этот контакт?",
                ReturnUrl          = Url.Action("Edit", new { id = contact.UserId }),
                AjaxUpdateTargetId = "uct_" + id,
                OnAjaxSuccess      = "HideModal"
            };

            return(View("~/Views/Shared/Dialogs/DeleteConfirmation.cshtml", model));
        }
Exemple #11
0
        public ActionResult EditContact(UserContactModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var repository = CurrentAccountDbContext.GetUserRepository();
            var contact    = repository.GetContactById(model.Id);

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

            repository.EditContactById(model.Id, model.Type, model.Value);

            if (model.ModalMode)
            {
                return(PartialView("UserContactData", contact));
            }

            return(Redirect(model.ReturnUrl));
        }
Exemple #12
0
        public ActionResult AddContact(UserContactModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var repository = CurrentAccountDbContext.GetUserRepository();
            var userId     = model.UserId;
            var user       = repository.GetById(userId);

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

            var contact = repository.AddContactToUser(user.Id, model.Type, model.Value, MvcApplication.GetServerDateTime());

            if (model.ModalMode)
            {
                return(PartialView("UserContactRow", contact));
            }

            return(Redirect(model.ReturnUrl));
        }
Exemple #13
0
        public ActionResult Index(Guid?componentId = null, string fromDate = null, string toDate = null,
                                  string category  = null, string channel  = null, string status = null, Guid?userId = null)
        {
            var sDate = !string.IsNullOrEmpty(fromDate) ? DecodeDateTimeParameter(fromDate) : (DateTime?)null;
            var eDate = !string.IsNullOrEmpty(toDate) ? DecodeDateTimeParameter(toDate) : (DateTime?)null;

            var eventCategory = EnumHelper.StringToEnum <EventCategory>(category);
            var nChannel      = EnumHelper.StringToEnum <NotificationType>(channel);
            var nStatus       = EnumHelper.StringToEnum <NotificationStatus>(status);

            var componentRepository = CurrentAccountDbContext.GetComponentRepository();
            var userRepository      = CurrentAccountDbContext.GetUserRepository();

            if (!CurrentUser.CanManageAccount())
            {
                userId = CurrentUser.Id;
            }

            if (userId.HasValue)
            {
                userRepository.GetById(userId.Value);
            }

            var users = userRepository.QueryAll().ToArray();
            var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventTypes          = eventTypeRepository.QueryAll().ToArray();
            var allComponents       = componentRepository.QueryAllWithDeleted();

            var notificationRepository = CurrentAccountDbContext.GetNotificationRepository();
            var query = notificationRepository.QueryAllForGui(componentId, sDate, eDate, eventCategory, nChannel, nStatus, userId);

            query = query.OrderByDescending(t => t.CreationDate).Take(1000);
            var notifications = query.ToArray()
                                .Join(users, a => a.UserId, b => b.Id, (a, b) => new { Notification = a, User = b })
                                .Join(eventTypes, a => a.Notification.Event.EventTypeId, b => b.Id,
                                      (a, b) => new { Notification = a, EventType = b })
                                .Select(t => new NotificationsListItemModel()
            {
                Id           = t.Notification.Notification.Id,
                CreationDate = t.Notification.Notification.CreationDate,
                Event        = t.Notification.Notification.Event,
                User         = t.Notification.User,
                Component    = allComponents.Single(x => x.Id == t.Notification.Notification.Event.OwnerId),
                Address      = t.Notification.Notification.Address,
                Channel      = t.Notification.Notification.Type,
                Status       = t.Notification.Notification.Status,
                SendError    = t.Notification.Notification.SendError,
                SendDate     = t.Notification.Notification.SendDate,
                NextDate     = null,
                EventType    = t.EventType
            });

            var model = new NotificationsListModel()
            {
                AccountId     = CurrentUser.AccountId,
                ComponentId   = componentId,
                FromDate      = sDate,
                ToDate        = eDate,
                Category      = eventCategory,
                Channel       = nChannel,
                Status        = nStatus,
                UserId        = userId,
                Notifications = notifications.OrderByDescending(t => t.CreationDate).ToList()
            };

            return(View(model));
        }