コード例 #1
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));
        }
コード例 #2
0
        /// <summary>
        /// Редактирует подписку
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(Guid id)
        {
            var subscriptionRepository = CurrentAccountDbContext.GetSubscriptionRepository();
            var subscription           = subscriptionRepository.GetById(id);
            var model = new SubscriptionEditModel()
            {
                ModalMode            = Request.IsAjaxRequest(),
                ReturnUrl            = Url.Action("Index", new { userId = subscription.UserId }),
                Id                   = subscription.Id,
                Object               = subscription.Object,
                NotifyBetterStatus   = subscription.NotifyBetterStatus,
                UserId               = subscription.UserId,
                ComponentTypeId      = subscription.ComponentTypeId,
                ComponentId          = subscription.ComponentId,
                Channel              = subscription.Channel,
                CanShowChannel       = false,
                CanShowComponentType = false,
                CanShowComponent     = false,
                IsEnabled            = subscription.IsEnabled,
                Color                = ColorStatusSelectorValue.FromEventImportance(subscription.Importance),
                MinimumDuration      = TimeSpanHelper.FromSeconds(subscription.DurationMinimumInSeconds),
                ResendTime           = TimeSpanHelper.FromSeconds(subscription.ResendTimeInSeconds)
            };

            return(View(model));
        }
コード例 #3
0
        public ActionResult EditComponentSubscriptions(
            Guid componentId,
            Guid?userId)
        {
            var component = GetComponentById(componentId);

            userId = userId ?? CurrentUser.Id;
            var user = GetUserById(userId.Value);

            var subscriptions = CurrentAccountDbContext
                                .GetSubscriptionRepository()
                                .QueryAll()
                                .Where(x => x.UserId == userId &&
                                       (x.Object == SubscriptionObject.Default ||
                                        (x.Object == SubscriptionObject.ComponentType && x.ComponentTypeId == component.ComponentTypeId) ||
                                        (x.Object == SubscriptionObject.Component && x.ComponentId == componentId)))
                                .ToArray();


            var model = new EditComponentSubscriptionsModel()
            {
                Component        = component,
                User             = user,
                AllSubscriptions = subscriptions
            };

            return(View(model));
        }
コード例 #4
0
        public ActionResult Color(string ids, string color, Guid userId, SubscriptionChannel channel)
        {
            var colorValue = ColorStatusSelectorValue.FromString(color);
            var colors     = colorValue.GetSelectedEventImportances();

            var subscriptionRepository = CurrentAccountDbContext.GetSubscriptionRepository();

            var list = ids.Split(',');

            foreach (var item in list)
            {
                var id = new Guid(item);

                var subscription = subscriptionRepository.GetById(id);
                CheckEditingPermissions(subscription);

                var client   = GetDispatcherClient();
                var response = client.CreateSubscription(CurrentUser.AccountId, new CreateSubscriptionRequestData()
                {
                    UserId          = subscription.UserId,
                    ComponentTypeId = subscription.ComponentTypeId,
                    Channel         = subscription.Channel,
                    Object          = subscription.Object
                });
                var data = response.Data;

                var response2 = client.UpdateSubscription(CurrentUser.AccountId, new UpdateSubscriptionRequestData()
                {
                    Id         = data.Id,
                    IsEnabled  = data.IsEnabled,
                    Importance = colors.Count > 0 ? colors[0] : data.Importance,
                    DurationMinimumInSeconds = data.DurationMinimumInSeconds,
                    ResendTimeInSeconds      = data.ResendTimeInSeconds
                });
                response2.Check();
            }

            if (Request.IsAjaxRequest())
            {
                return(new EmptyResult());
            }

            return(RedirectToAction("Index", new { userId = userId, channel = channel }));
        }
コード例 #5
0
        public ActionResult Delete(DeleteConfirmationSmartModel model)
        {
            try
            {
                // TODO Удаление подписок нужно делать через Диспетчер

                var repository   = CurrentAccountDbContext.GetSubscriptionRepository();
                var subscription = repository.GetById(model.Id);
                CheckEditingPermissions(subscription);

                var subscriptionService = new SubscriptionService(DbContext);
                subscriptionService.Remove(CurrentUser.AccountId, subscription);

                CurrentAccountDbContext.SaveChanges();
                return(GetSuccessJsonResponse());
            }
            catch (Exception exception)
            {
                MvcApplication.HandleException(exception);
                return(GetErrorJsonResponse(exception));
            }
        }
コード例 #6
0
        public ActionResult Index(Guid?userId = null)
        {
            // получаем пользователя
            if (userId == null)
            {
                userId = CurrentUser.Id;
            }

            // получаем подписки
            var subscriptions = CurrentAccountDbContext.GetSubscriptionRepository()
                                .QueryAll()
                                .Where(x => x.UserId == userId.Value)
                                .Where(x => x.Channel == SubscriptionChannel.Email || x.Channel == SubscriptionChannel.Sms)
                                .ToArray();

            var model = new SubscriptionListModel()
            {
                UserId        = userId.Value,
                Subscriptions = subscriptions
            };

            return(View(model));
        }