Пример #1
0
        public async Task <IActionResult> InsertLog([FromBody][Required] PostLogRequestDto data)
        {
            StatusResponseDto responseDto;

            try
            {
                responseDto = new StatusResponseDto();

                DateTime dtNow = DateTime.UtcNow;

                LogsGenerals LogPetition = new LogsGenerals
                {
                    TypeLog     = data.TypeLog,
                    Description = data.Description,
                    HourLog     = dtNow,
                    UserId      = data.UserId,
                    CallsId     = data.CallsId
                };

                _securityService.InsertLog(LogPetition);

                responseDto.Status = "OK";
                return(StatusCode(StatusCodes.Status200OK, responseDto));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Пример #2
0
        public IActionResult GetCallsByCommercials([FromQuery][Required] string commercial_id, [FromQuery] string days)
        {
            StatusResponseDto responseDto;

            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/bo/calls/GetCallsByCommercials: {commercial_id: " + commercial_id + ", days: " + days + "}");

                if (string.IsNullOrWhiteSpace(commercial_id))
                {
                    return(BadRequest());
                }

                if (string.IsNullOrWhiteSpace(days))
                {
                    days = "7";
                }

                if (!int.TryParse(days, out int pdays))
                {
                    responseDto = new StatusResponseDto
                    {
                        Status  = "BadRequest",
                        Message = "Datos de entrada incorrectos."
                    };
                    return(StatusCode(StatusCodes.Status400BadRequest, responseDto));
                }

                GetBOCallsByCommercialResponseModel responseModel = _boCallsService.GetCallsByCommercials(int.Parse(commercial_id), pdays);
                switch (responseModel.Status)
                {
                case ResultStatus.SUCCESS:
                    List <GetCallsRecentsByCommercialDto> response200Dto = _mapper.Map <List <GetCallsRecentsByCommercialDto> >(responseModel.ListCustomer);
                    return(StatusCode(StatusCodes.Status200OK, response200Dto));

                case ResultStatus.BAD_REQUEST:
                    // Datos entrada incorrectos
                    responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status400BadRequest, responseDto));

                default:
                    // Error interno
                    responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
                }
            }

            catch (Exception e)
            {
                responseDto = new StatusResponseDto
                {
                    Status  = "ERROR",
                    Message = "[BOCallsController-Bycommercial-Exception: " + e.Message
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
            }
        }
Пример #3
0
        public async Task <StatusResponseDto> ObterStatus(StatusPedidoDto statusPedido)
        {
            var pedidoEntity = await ObterPorId(statusPedido.Pedido);

            var response = new StatusResponseDto {
                Pedido = statusPedido.Pedido
            };

            if (pedidoEntity == null)
            {
                response.Status.Add(Status.CodigoPedidoInvalido.Value);

                return(response);
            }

            if (statusPedido.Status.Equals(Status.Reprovado.Value))
            {
                response.Status.Add(Status.Reprovado.Value);

                return(response);
            }

            decimal valorTotalItens = pedidoEntity.Itens.Sum(item => item.PrecoUnitario * item.Qtd);
            int     qtdTotalItens   = pedidoEntity.Itens.Sum(item => item.Qtd);

            if (statusPedido.Status.Equals(Status.Aprovado.Value))
            {
                if (statusPedido.ItensAprovados == qtdTotalItens && statusPedido.ValorAprovado == valorTotalItens)
                {
                    response.Status.Add(Status.Aprovado.Value);
                    return(response);
                }

                if (statusPedido.ValorAprovado < valorTotalItens)
                {
                    response.Status.Add(Status.AprovadoValorAMenor.Value);
                }

                if (statusPedido.ValorAprovado < valorTotalItens)
                {
                    response.Status.Add(Status.AprovadoValorAMaior.Value);
                }

                if (statusPedido.ItensAprovados < qtdTotalItens)
                {
                    response.Status.Add(Status.AprovadoQtdMenor.Value);
                }

                if (statusPedido.ItensAprovados > qtdTotalItens)
                {
                    response.Status.Add(Status.AprovadoQtdMaior.Value);
                }
            }

            return(response);
        }
Пример #4
0
            public void CallGetEndPointDeserializerExceptionThrowsServiceCallFailedException()
            {
                //Arrange
                var serviceCallResult = new StatusResponseDto
                {
                    IsSuccess = true,
                    ContinueProcessing = true
                };
                _httpClientMock.Setup(x => x.GetStringAsync(It.IsAny<string>())).ReturnsAsync(Serializer.SerializeO(serviceCallResult));

                //Act and Verify
                CheckForEviivoException<ServiceCallFailedException>(() => _client.CallGetEndPoint<string>(string.Empty), "Supplying the wrong type to the REST Service Client ", "SRVEX30136");
            }
        public ActionResult <StatusResponseDto> GetStatus()
        {
            var status = new StatusResponseDto
            {
                AssemblyInfoVersion = this.GetType().Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion,
                AssemblyVersion     = this.GetType().Assembly.GetName().Version.ToString(),
                AssemblyFileVersion = this.GetType().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version,

                MachineName     = Environment.MachineName,
                EnvironmentName = this.environment?.EnvironmentName ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
            };

            return(Ok(status));
        }
Пример #6
0
            public void CallGetEndPointReturnsCorrectly()
            {
                //Arrange
                var serviceCallResult = new StatusResponseDto
                {
                    IsSuccess = true,
                    ContinueProcessing = true
                };
                _httpClientMock.Setup(x => x.GetStringAsync(It.IsAny<string>())).ReturnsAsync(Serializer.SerializeO(serviceCallResult));

                //Act
                var result = _client.CallGetEndPoint<StatusResponseDto>(string.Empty);

                //Assert
                Assert.AreEqual(serviceCallResult.IsSuccess, result.IsSuccess);
                Assert.AreEqual(serviceCallResult.ContinueProcessing, result.ContinueProcessing);
            }
Пример #7
0
        public IActionResult GetCallDetails([FromRoute][Required] int id)
        {
            StatusResponseDto statusResponseDto;

            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/bo/calls/GetCallDetails: " + JsonConvert.SerializeObject(id));

                string fileServerURL = _config.GetValue <string>("FileServer:URL");
                string fileServerDir = _config.GetValue <string>("FileServer:Dir");
                string path          = System.IO.Path.Combine(fileServerURL, fileServerDir); // directorio donde se alojan los audios
                GetBOCallDetailsResponseModel businessResponse = _boCallsService.GetCallDetails(id, path);

                switch (businessResponse.Status)
                {
                case ResultStatus.SUCCESS:
                    GetBOCallDetailsResponseDto response;
                    response         = _mapper.Map <GetBOCallDetailsResponseDto>(businessResponse.Info);
                    response.Parts   = _mapper.Map <List <BOCallPartsDto> >(businessResponse.Parts);
                    response.Records = _mapper.Map <List <CallsRecodsResponseDto> >(businessResponse.Records);
                    return(StatusCode(StatusCodes.Status200OK, response));

                case ResultStatus.NOT_FOUND:
                    statusResponseDto = _mapper.Map <StatusResponseDto>(businessResponse);
                    return(StatusCode(StatusCodes.Status404NotFound));

                default:
                    statusResponseDto = _mapper.Map <StatusResponseDto>(businessResponse);
                    return(StatusCode(StatusCodes.Status500InternalServerError, statusResponseDto));
                }
            }
            catch (Exception e)
            {
                statusResponseDto = new StatusResponseDto
                {
                    Status  = "ERROR",
                    Message = "[BOCallsController-GetCallDetails-Exception: " + e.Message
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, statusResponseDto));
            }
        }
Пример #8
0
        public IActionResult GetApiVersion()
        {
            try
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                string version = fvi.ProductVersion;

                return(StatusCode(StatusCodes.Status200OK, version));
            }
            catch (Exception e)
            {
                StatusResponseDto responseDto = new StatusResponseDto
                {
                    Status  = "ERROR",
                    Message = "[ApiInfoController-GetApiVersion-Exception: " + e.Message
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
            }
        }
Пример #9
0
        public IActionResult CreateSupervisor([FromBody][Required] PostBOSupervisorRequestDto data)
        {
            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/bo/supervisors/CreateSupervisor: " + JsonConvert.SerializeObject(data));

                PostBOSupervisorRequestModel  request          = _mapper.Map <PostBOSupervisorRequestModel>(data);
                PostBOSupervisorResponseModel businessResponse = _boSupervisorService.CreateSupervisor(request);

                switch (businessResponse.Status)
                {
                case ResultStatus.SUCCESS:
                    return(Ok());

                case ResultStatus.BAD_REQUEST:
                    return(BadRequest());

                case ResultStatus.ACCESS_DENIED:
                    return(StatusCode(StatusCodes.Status401Unauthorized));

                case ResultStatus.NOT_AUTHORIZED:
                    return(StatusCode(StatusCodes.Status403Forbidden));

                case ResultStatus.NOT_NULL:
                case ResultStatus.SUPERVISOR_ROW_DUPLICATE:
                case ResultStatus.SUPERVISOR_ROW_DUPLICATE_EMAIL:
                    StatusResponseDto responseDto = _mapper.Map <StatusResponseDto>(businessResponse);
                    return(StatusCode(StatusCodes.Status409Conflict, responseDto));

                default:
                    return(StatusCode(StatusCodes.Status500InternalServerError, businessResponse.Message));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Пример #10
0
        public IActionResult DeleteSupervisor([FromRoute][Required] int id)
        {
            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/bo/supervisors/DeleteSupervisor: " + JsonConvert.SerializeObject(id));

                StatusResponseModel responseModel = _boSupervisorService.DeleteSupervisor(id);
                switch (responseModel.Status)
                {
                case ResultStatus.SUCCESS:
                    return(Ok());

                case ResultStatus.BAD_REQUEST:
                    return(BadRequest());

                case ResultStatus.ACCESS_DENIED:
                    return(StatusCode(StatusCodes.Status401Unauthorized));

                case ResultStatus.NOT_AUTHORIZED:
                    return(StatusCode(StatusCodes.Status403Forbidden));

                case ResultStatus.CONFLICT:
                    StatusResponseDto responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status409Conflict, responseDto));

                case ResultStatus.NOT_FOUND:
                    return(NotFound());

                default:
                    return(StatusCode(StatusCodes.Status500InternalServerError, responseModel.Message));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Пример #11
0
        public IActionResult GenerateHash([FromBody][Required] PostCreateHash data)
        {
            StatusResponseDto responseDto;

            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                //_securityService.RequestLog("api/auth/GenerateHash: " + JsonConvert.SerializeObject(data));

                if (string.IsNullOrWhiteSpace(data.Data))
                {
                    return(BadRequest());
                }
                else
                {
                    var    request  = _mapper.Map <String>(data.Data);
                    string response = Utils.Encrypt(request);
                    if (!string.IsNullOrWhiteSpace(response))
                    {
                        responseDto = new StatusResponseDto
                        {
                            Message = response,
                            Status  = ResultStatus.SUCCESS.ToString()
                        };
                        return(StatusCode(StatusCodes.Status200OK, responseDto));
                    }

                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Пример #12
0
            public void CallGetEndPointDeserializerExceptionThrowsServiceCallFailedException()
            {
                //Arrange
                var serviceCallResult = new StatusResponseDto
                {
                    IsSuccess = true,
                    ContinueProcessing = true
                };
                _httpClientMock.Setup(x => x.PostAsXmlAsync(It.IsAny<string>(), It.IsAny<object>())).ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(Serializer.SerializeO(serviceCallResult))
                });

                //Act and Verify
                CheckForEviivoException<ServiceCallFailedException>(() => _client.CallPostEndPoint<string, object>(string.Empty, new object()), "Supplying the wrong type to the REST Service Client ", "SRVEX30136");
            }
Пример #13
0
            public void CallGetEndPointReturnsCorrectly()
            {
                //Arrange
                var serviceCallResult = new StatusResponseDto
                {
                    IsSuccess = true,
                    ContinueProcessing = true
                };
                _httpClientMock.Setup(x => x.PostAsXmlAsync(It.IsAny<string>(), It.IsAny<object>())).ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(Serializer.SerializeO(serviceCallResult))
                    });

                //Act
                var result = _client.CallPostEndPoint<StatusResponseDto, object>(string.Empty, new object());

                //Assert
                Assert.AreEqual(serviceCallResult.IsSuccess, result.IsSuccess);
                Assert.AreEqual(serviceCallResult.ContinueProcessing, result.ContinueProcessing);
            }
        public IActionResult PutUpdateCommercial([FromRoute][Required] int id, [FromBody][Required] PutCommercialRequestDto data)
        {
            StatusResponseDto responseDto;

            try
            {
                /// <summary>
                /// Metodo para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/bo/commercials/PutUpdateCommercial: {id: " + JsonConvert.SerializeObject(id) + ", data: " + JsonConvert.SerializeObject(data) + "}");

                #region Validacion datos entrada
                bool error = false;
                responseDto = new StatusResponseDto();

                if (!error && (!ModelState.IsValid || id != data.CommercialId))
                {
                    responseDto.Status  = "PAYLOAD_INVALID";
                    responseDto.Message = "The payload is invalid or check the commercial id on route and payload.";
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.SiebelId))
                {
                    responseDto.Status  = "SIEBEL_ID_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "SiebelId");
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.PBXPhoneNumber))
                {
                    responseDto.Status  = "PBX_NUMBER_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "PBX Number");
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.MobilePhoneNumber))
                {
                    responseDto.Status  = "MOBILE_NUMBER_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "Mobile Number");
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.CommercialName))
                {
                    responseDto.Status  = "NAME_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "Name");
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.CommercialEmail))
                {
                    responseDto.Status  = "EMAIL_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "Email");
                    error = true;
                }

                if (!error && data.CommercialEmail.Length > Constants.Commercials_Email_MaxLen)
                {
                    responseDto.Status  = "EMAIL_MAX_LEN";
                    responseDto.Message = string.Format("The maximum length of the field '{0}' is {1}.", "Email", Constants.Commercials_Email_MaxLen);
                    error = true;
                }

                if (!error && data.CommercialName.Length > Constants.Commercials_Name_MaxLen)
                {
                    responseDto.Status  = "NAME_MAX_LEN";
                    responseDto.Message = string.Format("The maximum length of the field '{0}' is {1}.", "Name", Constants.Commercials_Name_MaxLen);
                    error = true;
                }

                if (!error && data.SiebelId.Length > Constants.Commercials_SiebelId_MaxLen)
                {
                    responseDto.Status  = "SIEBEL_ID_MAX_LEN";
                    responseDto.Message = string.Format("The maximum length of the field '{0}' is {1}.", "Siebel Id", Constants.Commercials_SiebelId_MaxLen);
                    error = true;
                }

                if (!error && data.PBXPhoneNumber.Length > Constants.Commercials_PBXNumber_MaxLen)
                {
                    responseDto.Status  = "PBX_NUMBER_MAX_LEN";
                    responseDto.Message = string.Format("The maximum length of the field '{0}' is {1}.", "PBX Number", Constants.Commercials_PBXNumber_MaxLen);
                    error = true;
                }

                if (!error && data.MobilePhoneNumber.Length > Constants.Commercials_MobilePhoneNumber_MaxLen)
                {
                    responseDto.Status  = "MOBILE_NUMBER_MAX_LEN";
                    responseDto.Message = string.Format("The maximum length of the field '{0}' is {1}.", "Mobile Number", Constants.Commercials_MobilePhoneNumber_MaxLen);
                    error = true;
                }

                if (error)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, responseDto));
                }
                #endregion

                var commercialModel = _mapper.Map <PutCommercialRequestModel>(data);
                StatusResponseModel businessResult = _boCommercialService.UpdateCommercial(id, commercialModel);
                responseDto = _mapper.Map <StatusResponseDto>(businessResult);
                switch (businessResult.Status)
                {
                case ResultStatus.SUCCESS:
                    return(StatusCode(StatusCodes.Status200OK, responseDto));

                case ResultStatus.CANNOT_CONNECT_TO_PBX:
                case ResultStatus.EXTERNAL_SERVICE_ERROR:
                    return(StatusCode(StatusCodes.Status503ServiceUnavailable, responseDto));

                case ResultStatus.BAD_REQUEST:
                    return(StatusCode(StatusCodes.Status400BadRequest, responseDto));

                case ResultStatus.COMMERCIAL_ROW_DUPLICATE_EMAIL:
                case ResultStatus.COMMERCIAL_ROW_DUPLICATE_PEER:
                case ResultStatus.COMMERCIAL_ROW_DUPLICATE_PBX:
                case ResultStatus.COMMERCIAL_ROW_DUPLICATE_MOBILE:
                case ResultStatus.COMMERCIAL_ROW_DUPLICATE_SIEBELID:
                    return(StatusCode(StatusCodes.Status409Conflict, responseDto));

                case ResultStatus.NOT_FOUND:
                    return(StatusCode(StatusCodes.Status404NotFound, responseDto));

                default:
                    return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
                }
            }
            catch (Exception e)
            {
                responseDto = new StatusResponseDto
                {
                    Status  = "ERROR",
                    Message = "[BOCommercialsController-PutUpdateCommercial-Exception: " + e.Message
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
            }
        }
Пример #15
0
        public async Task <IActionResult> PostCallSetCustomerOutbound([FromBody][Required] PostCallsSetCustomerRequestDto data)
        {
            StatusResponseDto responseDto;

            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/bo/calls/PostCallSetCustomerOutbound: " + JsonConvert.SerializeObject(data));

                #region Validacion datos entrada
                bool error = false;
                responseDto = new StatusResponseDto();

                if (!error && string.IsNullOrWhiteSpace(data.CustomerId))
                {
                    responseDto.Status  = "CUSTOMER_ID_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "customer_id");
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.CustomerName))
                {
                    responseDto.Status  = "CUSTOMER_NAME_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "customer_name");
                    error = true;
                }

                if (error)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, responseDto));
                }
                #endregion

                var    callSetCustomerModel        = _mapper.Map <PostCallsSetCustomerRequestModel>(data);
                string endPoint                    = _config.GetValue <string>("ExternalServicesHosts:Siebel:EndPointEndCall");
                StatusResponseModel businessResult = await _boCallsService.SetCustomer(callSetCustomerModel, CallDirection.Outbound, endPoint);

                switch (businessResult.Status)
                {
                case ResultStatus.SUCCESS:
                    responseDto = _mapper.Map <StatusResponseDto>(businessResult);
                    return(StatusCode(StatusCodes.Status200OK, responseDto));

                case ResultStatus.BAD_REQUEST:
                    return(BadRequest());

                case ResultStatus.ACCESS_DENIED:
                    return(StatusCode(StatusCodes.Status401Unauthorized));

                case ResultStatus.NOT_AUTHORIZED:
                    return(StatusCode(StatusCodes.Status403Forbidden));

                case ResultStatus.NOT_FOUND:
                    return(NotFound());

                default:
                    return(StatusCode(StatusCodes.Status500InternalServerError, businessResult.Message));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Пример #16
0
        public IActionResult ChangePassword([FromBody][Required] PostUpdatePasswordRequestDto data)
        {
            StatusResponseDto responseDto;

            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/auth/ChangePassword: "******"PASSWORD_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "password");
                    error = true;
                }

                if (!error && string.IsNullOrWhiteSpace(data.NewPassword))
                {
                    responseDto.Status  = "NEW_PASSWORD_NULL_OR_WHITESPACE";
                    responseDto.Message = string.Format("The '{0}' field is required.", "new_password");
                    error = true;
                }

                if (error)
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, responseDto));
                }
                #endregion

                var changePasswordModel = _mapper.Map <PostUpdatePasswordRequestModel>(data);
                PostUpdatePasswordResponseModel responseModel = _authService.ChangePassword(changePasswordModel);
                switch (responseModel.Status)
                {
                case ResultStatus.SUCCESS:
                    PostUpdatePasswordResponse200Dto response200Dto = _mapper.Map <PostUpdatePasswordResponse200Dto>(responseModel);
                    return(StatusCode(StatusCodes.Status200OK, response200Dto));

                case ResultStatus.CONFLICT:
                    responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status409Conflict, responseDto));

                case ResultStatus.NOT_FOUND:
                    responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status404NotFound, responseDto));

                case ResultStatus.EXTERNAL_SERVICE_ERROR:
                case ResultStatus.CANNOT_CONNECT_TO_PBX:
                    responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status503ServiceUnavailable, responseDto));

                default:
                    responseDto = _mapper.Map <StatusResponseDto>(responseModel);
                    return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
                }
            }
            catch (Exception e)
            {
                responseDto = new StatusResponseDto
                {
                    Status  = "ERROR",
                    Message = "[AuthController-ChangePassword-Exception: " + e.Message
                };
                return(StatusCode(StatusCodes.Status500InternalServerError, responseDto));
            }
        }
Пример #17
0
        public IActionResult UploadCallPartFile([FromForm][Required] RequestUploadCallPartFileDto dataIn)
        {
            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/ipbxcalls/UploadCallPartFile: " + JsonConvert.SerializeObject(dataIn));

                if (!ModelState.IsValid || dataIn == null || dataIn.FileContent == null ||
                    string.IsNullOrWhiteSpace(dataIn.CallId) || string.IsNullOrWhiteSpace(dataIn.CallPartNumber))
                {
                    return(Ok(new StatusResponseDto
                    {
                        Status = "BadRequest",
                        Message = "Datos de entrada incorrectos."
                    }));
                }

                string uploadDir = _config.GetValue <string>("FileServer:Dir").Trim();
                if (string.IsNullOrEmpty(uploadDir))
                {
                    return(Ok(new StatusResponseDto()
                    {
                        Status = "Error",
                        Message = "En archivo appsettings no existe variable 'FileServer:Dir' o la misma es vacía."
                    }));
                }
                PostCallsUploadCallPartFileRequestModel request = new PostCallsUploadCallPartFileRequestModel()
                {
                    CallId         = dataIn.CallId,
                    CallPartNumber = dataIn.CallPartNumber,
                    PathToUpload   = string.Format("{0}", uploadDir),
                    FileContent    = dataIn.FileContent
                };

                // subida de archivo
                List <string> allowExtentions = _config.GetValue <string>("FileServer:FileType").Split(',').Select(s => s.Trim()).ToList();
                allowExtentions.Remove("");
                StatusResponseModel resUpdFile = _boCallsService.UploadCallPartFile_UploadFile(request, allowExtentions);
                switch (resUpdFile.Status)
                {
                case ResultStatus.SUCCESS:
                    // continuo con la actualizacion de la bd
                    break;

                case ResultStatus.BAD_REQUEST:
                case ResultStatus.ERROR:
                default:
                    StatusResponseDto responseDto = _mapper.Map <StatusResponseDto>(resUpdFile);
                    return(Ok(responseDto));
                }

                // actualizo tabla CallParts
                StatusResponseModel resUpdTable = _boCallsService.UploadCallPartFile_UpdateTable(request);
                switch (resUpdTable.Status)
                {
                case ResultStatus.SUCCESS:
                    return(Ok(new StatusResponseDto()
                    {
                        Status = "Ok",
                        Message = "Success"
                    }));

                case ResultStatus.BAD_REQUEST:
                case ResultStatus.ERROR:
                case ResultStatus.NOT_FOUND:
                default:
                    StatusResponseDto responseDto = _mapper.Map <StatusResponseDto>(resUpdTable);
                    return(Ok(responseDto));
                }
            }
            catch (Exception e)
            {
                return(Ok(new StatusResponseDto()
                {
                    Status = "Error",
                    Message = e.Message
                }));
            }
        }