예제 #1
0
        public async Task <IActionResult> CreateEventAsync([FromBody] EventEntity eventEntity, [FromQuery] string teamId)
        {
            this.RecordEvent("Create event- The HTTP POST call to create event has been initiated");

            if (string.IsNullOrEmpty(teamId))
            {
                this.logger.LogError("Team Id is either null or empty");
                this.RecordEvent("Create event- The HTTP POST call to create event has been failed");
                return(this.BadRequest(new { message = "Team Id is either null or empty" }));
            }

            var validationMessages = EventEntity.ValidateEventModel(eventEntity);

            if (validationMessages.Any())
            {
                this.logger.LogError("One or more validation failed for event details");
                this.RecordEvent("Create event- The HTTP POST call to create event has been failed");
                return(this.BadRequest(new { errors = validationMessages }));
            }

            eventEntity.CreatedBy = this.UserAadId;
            eventEntity.UpdatedBy = this.UserAadId;
            eventEntity.UpdatedOn = DateTime.UtcNow;
            eventEntity.TeamId    = teamId;

            try
            {
                var result = await this.eventWorkflowHelper.CreateNewEventAsync(eventEntity, this.UserName);

                if (result == null)
                {
                    this.RecordEvent("Create event- The HTTP POST call to create event has been failed");
                    this.logger.LogInformation($"Event {eventEntity.EventId} could not be found for team {eventEntity.TeamId}");
                    return(this.BadRequest(new { message = $"Event {eventEntity.EventId} not found for team {teamId}" }));
                }

                if (!(bool)result)
                {
                    this.RecordEvent("Create event- The HTTP POST call to create event has been failed");
                    this.logger.LogInformation($"Unable to create new event {eventEntity.EventId} for team {teamId}");
                }

                this.RecordEvent("Create event- The HTTP POST call to create event has been succeeded");

                return(this.Ok(result));
            }
            catch (Exception ex)
            {
                this.RecordEvent("Create event- The HTTP POST call to create event has been failed");
                this.logger.LogError(ex, $"Error occurred while creating event {eventEntity.EventId} not found for team {teamId}");
                throw;
            }
        }
예제 #2
0
        public async Task <IActionResult> UpdateAsync([FromBody] EventEntity eventEntity, [FromQuery] string teamId)
        {
            this.RecordEvent("Update Event- The HTTP PATCH call to update event details has been initiated");

            if (string.IsNullOrEmpty(teamId))
            {
                this.logger.LogError("Team Id is either null or empty");
                this.RecordEvent("Update event- The HTTP POST call to create event has been failed");
                return(this.BadRequest(new { message = "Team Id is either null or empty" }));
            }

            try
            {
                var validationMessages = EventEntity.ValidateEventModel(eventEntity, true);
                if (validationMessages.Any())
                {
                    this.logger.LogError("One or more validation failed for event details");
                    this.RecordEvent("Update event- The HTTP POST call to create event has been failed");
                    return(this.BadRequest(new { errors = validationMessages }));
                }

                eventEntity.UpdatedBy = this.UserAadId;
                eventEntity.UpdatedOn = DateTime.UtcNow;

                var result = await this.eventWorkflowHelper.UpdateEventAsync(eventEntity);

                if (result == null)
                {
                    this.RecordEvent("Update event- The HTTP PATCH call to update event has been failed");
                    this.logger.LogInformation($"Event {eventEntity.EventId} could not be found for team {eventEntity.TeamId}");
                    return(this.BadRequest(new { message = $"Event {eventEntity.EventId} not found for team {teamId}" }));
                }

                if (!(bool)result)
                {
                    this.RecordEvent("Update event- The HTTP POST call to create event has been failed");
                    this.logger.LogInformation($"Unable to update new event {eventEntity.EventId} for team {teamId}");
                }

                this.RecordEvent("Update event- The HTTP PATCH call to update event has been succeeded");

                return(this.Ok(result));
            }
            catch (Exception ex)
            {
#pragma warning disable CA1062 // Validation is done at model level
                this.RecordEvent(string.Format(CultureInfo.InvariantCulture, "Update Event- The HTTP PATCH call to update event {0} has been failed", eventEntity.EventId));
#pragma warning restore CA1062 // Validation is done at model level
                this.logger.LogError(ex, string.Format(CultureInfo.InvariantCulture, "Error occurred while updating event {0}", eventEntity.EventId));
                throw;
            }
        }
예제 #3
0
        public async Task <IActionResult> UpdateAsync([FromBody] EventEntity eventEntity, [FromQuery] string teamId)
        {
            this.RecordEvent("Update Event- The HTTP PATCH call to update event details has been initiated", new Dictionary <string, string>
            {
                { "eventId", eventEntity?.EventId },
                { "teamId", teamId },
            });

            if (string.IsNullOrEmpty(teamId))
            {
                this.logger.LogError("Team Id is either null or empty");
                this.RecordEvent("Update event- The HTTP POST call to create event has been failed", new Dictionary <string, string>
                {
                    { "eventId", eventEntity?.EventId },
                    { "teamId", teamId },
                });
                return(this.BadRequest(new ErrorResponse {
                    Message = "Team Id is either null or empty"
                }));
            }

            try
            {
                // Validate event details.
                var validationMessages = EventEntity.ValidateEventModel(eventEntity, this.localizer, true);
                if (validationMessages.Any())
                {
                    this.logger.LogError("One or more validation failed for event details");
                    this.RecordEvent("Update event- The HTTP POST call to create event has been failed", new Dictionary <string, string>
                    {
                        { "eventId", eventEntity?.EventId },
                        { "teamId", teamId },
                    });
                    return(this.BadRequest(new ErrorResponse {
                        Message = "One or more validation errors occurred", Errors = validationMessages
                    }));
                }

                // Assign logged in users' AAD object Id as it is available in controllers. All other properties will be mapped by EventWorkflowHelper.
                eventEntity.UpdatedBy = this.UserAadId;
                eventEntity.UpdatedOn = DateTime.UtcNow;

                var result = await this.eventWorkflowHelper.UpdateEventAsync(eventEntity);

                if (result == null)
                {
                    this.RecordEvent("Update event- The HTTP PATCH call to update event has been failed", new Dictionary <string, string>
                    {
                        { "eventId", eventEntity?.EventId },
                        { "teamId", teamId },
                    });
                    this.logger.LogInformation($"Event {eventEntity.EventId} could not be found for team {eventEntity.TeamId}");
                    return(this.BadRequest(new ErrorResponse {
                        Message = $"Event {eventEntity.EventId} not found for team {teamId}"
                    }));
                }

                if (!(bool)result)
                {
                    this.RecordEvent("Update event- The HTTP POST call to create event has been failed", new Dictionary <string, string>
                    {
                        { "eventId", eventEntity?.EventId },
                        { "teamId", teamId },
                    });
                    this.logger.LogInformation($"Unable to update new event {eventEntity.EventId} for team {teamId}");
                }

                this.RecordEvent("Update event- The HTTP PATCH call to update event has been succeeded", new Dictionary <string, string>
                {
                    { "eventId", eventEntity?.EventId },
                    { "teamId", teamId },
                });

                return(this.Ok(result));
            }
            catch (Exception ex)
            {
                this.RecordEvent("Update Event- The HTTP PATCH call to update event has been failed", new Dictionary <string, string>
                {
                    { "eventId", eventEntity?.EventId },
                    { "teamId", teamId },
                });
                this.logger.LogError(ex, $"Error occurred while updating event {eventEntity.EventId}");
                throw;
            }
        }