Пример #1
0
        public async Task <ActionResult> Post([FromBody, Bind("ProviderId, CoordinatorId, UpdateAction")] Notification notification)
        {
            try
            {
                _logger.LogInformation($"POST - Making notification for notification ID {notification.NotificationId}." +
                                       $" Provider ID: {notification.ProviderId}\n Coordinator ID: {notification.CoordinatorId}");

                Lib.Model.Notification mappedNotification = new Lib.Model.Notification()
                {
                    ProviderId    = notification.ProviderId,
                    CoordinatorId = notification.CoordinatorId,
                    UpdateAction  = new UpdateAction
                    {
                        UpdateType       = notification.UpdateAction.UpdateType,
                        SerializedTarget = notification.UpdateAction.SerializedTarget
                    },
                    Status = new Status {
                        StatusText = Status.Pending
                    },
                    CreatedAt = DateTime.Now.AddDays(7)
                };
                mappedNotification.UpdateAction.NotificationId = mappedNotification.NotificationId;

                _repo.AddNotification(mappedNotification);
                await _repo.SaveAsync();

                _logger.LogInformation($"Persisted notification {notification.NotificationId}");
                return(Created("GetNotificationsByCoordinatorId", mappedNotification));
            }
            catch (Exception e)
            {
                _logger.LogError("Post request failed with exception: " + e.Message);
                return(BadRequest());
            }
        }