public IHttpActionResult DeleteOccurrence(int occurrenceId) { OccurrenceRequest request = new OccurrenceRequest { OccurrenceDto = new OccurrenceDto { OccurrenceId = occurrenceId } }; List <string> errors = ValidateOccurrenceId(request); OccurrenceMessage message = new OccurrenceMessage(); if (errors != null && errors.Any()) { message.ErrorMessage = OccurrenceMessageResource.ValidationErrors; message.ErrorType = ErrorType.ValidationError; message.Errors = new List <string>(); message.OperationSuccess = false; message.Errors.AddRange(errors); } else { message = _serviceOccurrenceClient.DeleteOccurrence(request); } return(Json(message)); }
/// <summary> /// From Occurrence Request to Occurrence Request pivot. /// </summary> /// <param name="occurrenceRequest"></param> /// <returns>Occurrence Request pivot result.</returns> public static OccurrenceRequestPivot ToPivot(this OccurrenceRequest occurrenceRequest) { return(new OccurrenceRequestPivot { FindOccurrencePivot = Utility.EnumToEnum <FindOccurrenceDto, FindOccurrencePivot>(occurrenceRequest.FindOccurrenceDto), OccurrencePivot = occurrenceRequest.OccurrenceDto.ToPivot() }); }
/// <summary> /// Validation delete occurrence. /// </summary> /// <param name="request">the request to validate.</param> /// <returns>errors validation</returns> private List <string> ValidateOccurrenceId(OccurrenceRequest request) { var errors = new List <string>(); if (request?.OccurrenceDto == null) { errors.Add(OccurrenceMessageResource.NullRequest); } else { errors.AddRange(GenericValidationAttribute <OccurrenceDto> .ValidateAttributes("OccurrenceId", request.OccurrenceDto.OccurrenceId.ToString())); } return(errors); }
/// <summary> /// Delete Occurrence /// </summary> /// <param name="request">occurrence request.</param> /// <returns>Occurrence message.</returns> public OccurrenceMessage DeleteOccurrence(OccurrenceRequest request) { OccurrenceMessage message = new OccurrenceMessage(); try { _serviceOccurrence.DeleteOccurrence(request.ToPivot()); message.OperationSuccess = true; } catch (Exception e) { message.ErrorType = ErrorType.TechnicalError; message.ErrorMessage = e.Message; } return(message); }
/// <summary> /// Validation creation occurrence. /// </summary> /// <param name="request">the request to validate.</param> /// <returns>errors validation</returns> private List <string> ValidateCreateOccurrence(OccurrenceRequest request) { var errors = new List <string>(); if (request?.OccurrenceDto == null) { errors.Add(OccurrenceMessageResource.NullRequest); } else { errors.AddRange(GenericValidationAttribute <OccurrenceDto> .ValidateAttributes("OccurrenceStartDate", request.OccurrenceDto.OccurrenceStartDate.ToString("dd/MM/yyyy"))); errors.AddRange(GenericValidationAttribute <OccurrenceDto> .ValidateAttributes("OccurrenceEndDate", request.OccurrenceDto.OccurrenceEndDate.ToString("dd/MM/yyyy"))); errors.AddRange(GenericValidationAttribute <OccurrenceDto> .ValidateAttributes("OccurrenceLink", request.OccurrenceDto.OccurrenceLink)); } return(errors); }