/// <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)); }
public void EditTest() { // Создадим пользователя var account = TestHelper.GetTestAccount(); var user = TestHelper.CreateTestUser(account.Id); var dispatcher = TestHelper.GetDispatcherClient(); var channels = new[] { SubscriptionChannel.Email, SubscriptionChannel.Sms, SubscriptionChannel.Http }; foreach (var channel in channels) { // Получим подписку по умолчанию var response = dispatcher.CreateSubscription(account.Id, new CreateSubscriptionRequestData() { UserId = user.Id, Object = SubscriptionObject.Default, Channel = channel }); var defaultSubscription = response.Data; // Изменим подписку по умолчанию SubscriptionEditModel model; using (var controller = new SubscriptionsController(account.Id, user.Id)) { var result = (ViewResultBase)controller.Edit(defaultSubscription.Id); model = (SubscriptionEditModel)result.Model; } model.ReturnUrl = "/"; model.IsEnabled = !model.IsEnabled; model.Color = ColorStatusSelectorValue.FromEventImportance(EventImportance.Success); model.MinimumDuration = TimeSpan.FromSeconds(10); model.ResendTime = TimeSpan.FromSeconds(20); using (var controller = new SubscriptionsController(account.Id, user.Id)) { controller.Edit(model); } // Проверим подписку по умолчанию var response2 = dispatcher.CreateSubscription(account.Id, new CreateSubscriptionRequestData() { UserId = user.Id, Object = SubscriptionObject.Default, Channel = channel }); var newDefaultSubscription = response2.Data; Assert.Equal(model.IsEnabled, newDefaultSubscription.IsEnabled); Assert.Equal(EventImportance.Success, newDefaultSubscription.Importance); Assert.Equal(10, newDefaultSubscription.DurationMinimumInSeconds); Assert.Equal(20, newDefaultSubscription.ResendTimeInSeconds); } }