Пример #1
0
        public async Task ExecuteAsync(MarkAsRead command)
        {
            var msg = await _repository.GetById(command.Notification.Id);

            msg.Status = NotificationInfo.NotificationStatus.ReadCompleted;

            await _eventsPublisher.PublishAsync(new NotificationWasMarkedAsRead { Notification = command.Notification });
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] Notification notification)
        {
            if (id != notification.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var notificationDb = await _repository.GetById(id);

                    if (notificationDb == null)
                    {
                        return(NotFound());
                    }
                    notification.OwnerID = notificationDb.OwnerID;

                    if (!await CheckIfUserAuthorizedForNotification(notification, NotificatinOperations.Update))
                    {
                        return(Forbid());
                    }
                    _repository.Update(notification);
                    await _repository.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NotificationExists(notification.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(notification));
        }