public async Task <IActionResult> EnviarAlCliente(AppGeneralQuotesChangeStatusDto dto) { Metadata metadata = new Metadata { IsValid = false, Message = "", TotalCount = 0 }; try { var generalQuotes = await _appGeneralQuotesService.EnviarAlCliente(dto); return(Ok(generalQuotes)); } catch (Exception e) { metadata.IsValid = false; metadata.Message = e.InnerException.Message; var responseError = new ApiResponse <AppGeneralQuotesGetDto>(null) { Meta = metadata }; return(Ok(responseError)); } }
public async Task <ApiResponse <AppGeneralQuotesGetDto> > EnviarAlCliente(AppGeneralQuotesChangeStatusDto dto) { AppGeneralQuotesGetDto resultDto = new AppGeneralQuotesGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppGeneralQuotesGetDto> response = new ApiResponse <AppGeneralQuotesGetDto>(resultDto); try { AppGeneralQuotes appGeneralQuotes = await GetById(dto.Id); if (appGeneralQuotes == null) { metadata.IsValid = false; metadata.Message = "Cotizacion No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } if (appGeneralQuotes.IdEstatus != 1) { metadata.IsValid = false; metadata.Message = "Cotizacion No esta en grabacion!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } ApiResponse <List <AppDetailQuotesGetDto> > appDatailQuotes = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(dto.Id); if (appDatailQuotes.Data.Count > 0) { foreach (AppDetailQuotesGetDto item in appDatailQuotes.Data) { AppDetailQuotes detailQuotes = await _appDetailQuotesService.GetById(item.Id); if (detailQuotes != null) { if (detailQuotes.PrecioUsd < detailQuotes.UnitPriceConverted) { metadata.IsValid = false; metadata.Message = "Precio de Venta es menor a la Lista..Enviar a Aprobacion!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } detailQuotes.IdEstatus = 2; await _appDetailQuotesService.Update(detailQuotes); } } appGeneralQuotes.IdEstatus = 2; AppGeneralQuotes AppGeneralQuotesUpdated = await Update(appGeneralQuotes); await _cotizacionService.IntegrarCotizacion(appGeneralQuotes.Id); AppGeneralQuotesQueryFilter filters = new AppGeneralQuotesQueryFilter { Cotizacion = appGeneralQuotes.Cotizacion }; resultDto = await GetAppGeneralQuotes(filters); metadata.IsValid = true; metadata.Message = "Cotizacion Enviada al cliente!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } else { metadata.IsValid = false; metadata.Message = "Cotizacion No tiene Productos cargados!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Meta = metadata; response.Data = resultDto; return(response); } }