public async Task <AppGeneralQuotesGetDto> GetAppGeneralQuotes(AppGeneralQuotesQueryFilter filters) { filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber; filters.PageSize = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize; AppGeneralQuotes quotes = await _unitOfWork.AppGeneralQuotesRepository.GetByCotizacions(filters.Cotizacion); if (quotes != null) { AppGeneralQuotesGetDto appGeneralQuotesGetDto = _mapper.Map <AppGeneralQuotesGetDto>(quotes); MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(appGeneralQuotesGetDto.IdVendedor); if (mtrVendedor != null) { MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor); appGeneralQuotesGetDto.MtrVendedorDto = mtrVendedorDto; } MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(appGeneralQuotesGetDto.IdCliente); if (mtrCliente != null) { MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente); appGeneralQuotesGetDto.MtrClienteDto = mtrClienteDto; } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(appGeneralQuotesGetDto.IdContacto); if (mtrContactos != null) { //MtrContactosDto mtrContactosDto = new MtrContactosDto(); //mtrContactosDto.IdContacto = mtrContactos.IdContacto; //mtrContactosDto.Cargo = mtrContactos.Email; MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos); appGeneralQuotesGetDto.MtrContactosDto = mtrContactosDto; } MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesGetDto.IdDireccionEntregar); if (direccionEntregar != null) { MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar); appGeneralQuotesGetDto.MtrDireccionesEntregarDto = direccionEntregarDto; } MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesGetDto.IdDireccionFacturar); if (direccionFacturar != null) { MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar); appGeneralQuotesGetDto.MtrDireccionesFacturarDto = direccionFacturarDto; } MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(appGeneralQuotesGetDto.IdCondPago); if (condicionPago != null) { CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago); appGeneralQuotesGetDto.CondicionPagoDto = condicionPagoDto; } MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(appGeneralQuotesGetDto.IdMtrTipoMoneda); if (mtrTipoMoneda != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda); appGeneralQuotesGetDto.MtrTipoMonedaDto = mtrTipoMonedaDto; } var actualizar = await _unitOfWork.AppGeneralQuotesRepository.VerificarStatus(appGeneralQuotesGetDto.Id); if (actualizar) { await _unitOfWork.SaveChangesAsync(); } AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotesGetDto.IdEstatus); if (appStatusQuote != null) { AppStatusQuoteGetDto appStatusQuoteDto = _mapper.Map <AppStatusQuoteGetDto>(appStatusQuote); appGeneralQuotesGetDto.AppStatusQuoteGetDto = appStatusQuoteDto; } appGeneralQuotesGetDto.PorcFlete = await GetFleteByIdDireccionEntrega(appGeneralQuotesGetDto.IdDireccionEntregar); var permiteAdicionarDetalle = await _unitOfWork.AppGeneralQuotesRepository.PermiteAdicionarDetalle(appGeneralQuotesGetDto.Id); appGeneralQuotesGetDto.PermiteAdicionarDetalle = permiteAdicionarDetalle; appGeneralQuotesGetDto.AppGeneralQuotesActionSheetDto = await GetAppGeneralQuotesActionSheetDto(appGeneralQuotesGetDto.Id); ApiResponse <List <AppDetailQuotesGetDto> > listDetail = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(appGeneralQuotesGetDto.Id); if (listDetail != null) { appGeneralQuotesGetDto.AppDetailQuotesGetDto = listDetail.Data; } return(appGeneralQuotesGetDto); } else { return(null); } }
public async Task <ApiResponse <AppGeneralQuotesGetDto> > UpdateGeneralQuotes(AppGeneralQuotesUpdateDto appGeneralQuotesUpdateDto) { AppGeneralQuotesGetDto resultDto = new AppGeneralQuotesGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppGeneralQuotesGetDto> response = new ApiResponse <AppGeneralQuotesGetDto>(resultDto); try { AppGeneralQuotes appGeneralQuotes = await GetById(appGeneralQuotesUpdateDto.Id); if (appGeneralQuotes == null) { metadata.IsValid = false; metadata.Message = "Cotizacion No Existe!!! " + appGeneralQuotesUpdateDto.Cotizacion; response.Meta = metadata; response.Data = resultDto; return(response); } MtrCliente cliente = await _mtrClienteService.GetByIdAsync(appGeneralQuotesUpdateDto.IdCliente); if (cliente == null) { metadata.IsValid = false; metadata.Message = "Cliente No Existe!!! " + appGeneralQuotesUpdateDto.IdCliente; response.Meta = metadata; response.Data = resultDto; return(response); } MtrDirecciones direccionEntregarValidate = await _unitOfWork.MtrDireccionesRepository.GetById(appGeneralQuotesUpdateDto.IdDireccionEntregar); if (direccionEntregarValidate == null) { metadata.IsValid = false; metadata.Message = "Direccion Entregar No Existe!!! " + appGeneralQuotesUpdateDto.IdDireccionEntregar; response.Meta = metadata; response.Data = resultDto; return(response); } MtrContactos mtrContactosValidate = await _unitOfWork.MtrContactosRepository.GetById(appGeneralQuotesUpdateDto.IdContacto); if (mtrContactosValidate == null) { metadata.IsValid = false; metadata.Message = "Contacto No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } MtrCondicionPago condicionPagoValidate = await _unitOfWork.MtrCondicionPagoRepository.GetById(appGeneralQuotesUpdateDto.IdCondPago); if (condicionPagoValidate == null) { metadata.IsValid = false; metadata.Message = "Condicion de Pago No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } MtrTipoMoneda mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById(appGeneralQuotesUpdateDto.IdMtrTipoMoneda); if (mtrTipoMonedaFind == null) { metadata.IsValid = false; metadata.Message = "Moneda No Existe!!! "; response.Meta = metadata; response.Data = resultDto; return(response); } if (appGeneralQuotesUpdateDto.OrdenCompra.Length > 16) { metadata.IsValid = false; metadata.Message = "Longitud Maxima de Orden de Compra es 16 !!! "; response.Meta = metadata; response.Data = resultDto; return(response); } if (appGeneralQuotesUpdateDto.IdCliente != "000000") { appGeneralQuotesUpdateDto.Rif = cliente.NoRegTribut; appGeneralQuotesUpdateDto.RazonSocial = cliente.Nombre; appGeneralQuotesUpdateDto.Direccion = cliente.Direccion + " " + cliente.Direccion1; } appGeneralQuotes.Rif = appGeneralQuotesUpdateDto.Rif; appGeneralQuotes.RazonSocial = appGeneralQuotesUpdateDto.RazonSocial; appGeneralQuotes.Direccion = appGeneralQuotesUpdateDto.Direccion; appGeneralQuotes.IdCliente = appGeneralQuotesUpdateDto.IdCliente; if (appGeneralQuotesUpdateDto.IdCliente == "000000") { appGeneralQuotes.IdMunicipio = appGeneralQuotesUpdateDto.IdMunicipio; var municipio = await _unitOfWork.Winy243Repository.GetById(appGeneralQuotesUpdateDto.IdMunicipio); if (municipio != null) { appGeneralQuotes.DescripcionMunicipio = municipio.DescMunicipio; } } else { var municipio = await _unitOfWork.Winy243Repository.GetByEstadoMunicipio(direccionEntregarValidate.Estado, direccionEntregarValidate.Municipio); if (municipio != null) { appGeneralQuotes.IdMunicipio = municipio.Recnum; appGeneralQuotes.DescripcionMunicipio = municipio.DescMunicipio; } } if (appGeneralQuotesUpdateDto.IdCliente != "000000") { appGeneralQuotes.IdVendedor = cliente.Vendedor1.Trim(); } else { appGeneralQuotes.IdVendedor = appGeneralQuotesUpdateDto.UsuarioActualiza; } appGeneralQuotes.Observaciones = appGeneralQuotesUpdateDto.Observaciones; appGeneralQuotes.IdCondPago = appGeneralQuotesUpdateDto.IdCondPago; appGeneralQuotes.IdContacto = appGeneralQuotesUpdateDto.IdContacto; appGeneralQuotes.IdDireccionFacturar = (decimal)cliente.IdDireccion; appGeneralQuotes.IdDireccionEntregar = appGeneralQuotesUpdateDto.IdDireccionEntregar; appGeneralQuotes.OrdenCompra = appGeneralQuotesUpdateDto.OrdenCompra; appGeneralQuotes.UsuarioActualiza = appGeneralQuotesUpdateDto.UsuarioActualiza; appGeneralQuotes.FechaActualiza = DateTime.Now; appGeneralQuotes.Proximo = 0; appGeneralQuotes.IdMtrTipoMoneda = appGeneralQuotesUpdateDto.IdMtrTipoMoneda; if (appGeneralQuotesUpdateDto.FechaPostergada != null) { appGeneralQuotes.FechaPostergada = appGeneralQuotesUpdateDto.FechaPostergada; } if (appGeneralQuotesUpdateDto.ObservacionPostergar != "" && appGeneralQuotesUpdateDto.ObservacionPostergar != null) { appGeneralQuotes.ObservacionPostergar = appGeneralQuotesUpdateDto.ObservacionPostergar; } else { appGeneralQuotesUpdateDto.ObservacionPostergar = ""; } appGeneralQuotes.FijarPrecioBs = appGeneralQuotesUpdateDto.FijarPrecioBs; AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(appGeneralQuotes.IdEstatus); MtrVendedor vendedor = _unitOfWork.MtrVendedorRepository.GetById(appGeneralQuotes.IdVendedor); if (appGeneralQuotesUpdateDto.IdCliente != "000000") { appGeneralQuotes.SearchText = $"{appGeneralQuotes.Cotizacion}-{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{cliente.Nombre.Trim()}{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{appGeneralQuotes.RazonSocial.Trim()}-{appStatusQuote.Descripcion.Trim()}"; } else { appGeneralQuotes.SearchText = $"{appGeneralQuotes.Cotizacion}-{appGeneralQuotes.IdVendedor}-{vendedor.Nombre.Trim()}-{appGeneralQuotes.IdCliente}-{appGeneralQuotes.RazonSocial.Trim()}-{appStatusQuote.Descripcion.Trim()}"; appGeneralQuotes.IdDireccionEntregar = 1; appGeneralQuotes.IdDireccionFacturar = 1; } AppGeneralQuotes AppGeneralQuotesUpdated = await Update(appGeneralQuotes); //await _cotizacionService.IntegrarCotizacion(AppGeneralQuotesUpdated.Id); if (AppGeneralQuotesUpdated != null) { resultDto = _mapper.Map <AppGeneralQuotesGetDto>(AppGeneralQuotesUpdated); MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(resultDto.IdVendedor); if (mtrVendedor != null) { MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor); resultDto.MtrVendedorDto = mtrVendedorDto; } MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(resultDto.IdCliente); if (mtrCliente != null) { MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente); resultDto.MtrClienteDto = mtrClienteDto; } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(resultDto.IdContacto); if (mtrContactos != null) { MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos); resultDto.MtrContactosDto = mtrContactosDto; } MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(resultDto.IdDireccionEntregar); if (direccionEntregar != null) { MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar); resultDto.MtrDireccionesEntregarDto = direccionEntregarDto; } MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(resultDto.IdDireccionFacturar); if (direccionFacturar != null) { MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar); resultDto.MtrDireccionesFacturarDto = direccionFacturarDto; } MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(resultDto.IdCondPago); if (condicionPago != null) { CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago); resultDto.CondicionPagoDto = condicionPagoDto; } MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(resultDto.IdMtrTipoMoneda); if (mtrTipoMoneda != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda); resultDto.MtrTipoMonedaDto = mtrTipoMonedaDto; } metadata.IsValid = true; metadata.Message = $"Cotizacion: {resultDto.Cotizacion} Actualizada Satisfactoriamente!!"; } else { metadata.IsValid = false; metadata.Message = "Registro No actualizado"; } 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); } }
public async Task <PagedList <AppGeneralQuotesGetDto> > GetAllAppGeneralQuotes(AppGeneralQuotesQueryFilter filters) { filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber; filters.PageSize = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize; List <AppGeneralQuotes> quotes = await _unitOfWork.AppGeneralQuotesRepository.GetAll(filters); if (quotes.Count > 0) { List <AppGeneralQuotesGetDto> appGeneralQuotesGetDto = _mapper.Map <List <AppGeneralQuotesGetDto> >(quotes); foreach (AppGeneralQuotesGetDto item in appGeneralQuotesGetDto) { MtrVendedor mtrVendedor = _unitOfWork.MtrVendedorRepository.GetById(item.IdVendedor); if (mtrVendedor != null) { MtrVendedorDto mtrVendedorDto = _mapper.Map <MtrVendedorDto>(mtrVendedor); item.MtrVendedorDto = mtrVendedorDto; } MtrCliente mtrCliente = _unitOfWork.MtrClienteRepository.GetById(item.IdCliente); if (mtrCliente != null) { MtrClienteDto mtrClienteDto = _mapper.Map <MtrClienteDto>(mtrCliente); item.MtrClienteDto = mtrClienteDto; if (item.IdCliente == "000000") { item.MtrClienteDto.Descripcion = item.IdCliente.Trim() + "-" + item.RazonSocial.Trim() + " RIF: " + item.Rif.ToString(); } } MtrContactos mtrContactos = await _unitOfWork.MtrContactosRepository.GetById(item.IdContacto); if (mtrContactos != null) { MtrContactosDto mtrContactosDto = _mapper.Map <MtrContactosDto>(mtrContactos); item.MtrContactosDto = mtrContactosDto; } MtrDirecciones direccionEntregar = await _unitOfWork.MtrDireccionesRepository.GetById(item.IdDireccionEntregar); if (direccionEntregar != null) { MtrDireccionesDto direccionEntregarDto = _mapper.Map <MtrDireccionesDto>(direccionEntregar); item.MtrDireccionesEntregarDto = direccionEntregarDto; } MtrDirecciones direccionFacturar = await _unitOfWork.MtrDireccionesRepository.GetById(item.IdDireccionFacturar); if (direccionFacturar != null) { MtrDireccionesDto direccionFacturarDto = _mapper.Map <MtrDireccionesDto>(direccionFacturar); item.MtrDireccionesFacturarDto = direccionFacturarDto; } MtrCondicionPago condicionPago = await _unitOfWork.MtrCondicionPagoRepository.GetById(item.IdCondPago); if (condicionPago != null) { CondicionPagoDto condicionPagoDto = _mapper.Map <CondicionPagoDto>(condicionPago); item.CondicionPagoDto = condicionPagoDto; } MtrTipoMoneda mtrTipoMoneda = await _unitOfWork.MtrTipoMonedaRepository.GetById(item.IdMtrTipoMoneda); if (mtrTipoMoneda != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(mtrTipoMoneda); item.MtrTipoMonedaDto = mtrTipoMonedaDto; } var actualizar = await _unitOfWork.AppGeneralQuotesRepository.VerificarStatus(item.Id); if (actualizar) { await _unitOfWork.SaveChangesAsync(); } AppStatusQuote appStatusQuote = await _unitOfWork.AppStatusQuoteRepository.GetById(item.IdEstatus); if (appStatusQuote != null) { AppStatusQuoteGetDto appStatusQuoteDto = _mapper.Map <AppStatusQuoteGetDto>(appStatusQuote); item.AppStatusQuoteGetDto = appStatusQuoteDto; } if (item.IdCliente == "000000") { var municipio = await _unitOfWork.Winy243Repository.GetById(item.IdMunicipio); if (municipio != null) { item.PorcFlete = municipio.PorcFlete; MunicipioGetDto municipioGetDto = _mapper.Map <MunicipioGetDto>(municipio); item.MunicipioGetDto = municipioGetDto; } } else { item.PorcFlete = await GetFleteByIdDireccionEntrega(item.IdDireccionEntregar); var municipio = await _unitOfWork.Winy243Repository.GetByEstadoMunicipio(direccionEntregar.Estado, direccionEntregar.Municipio); if (municipio != null) { item.IdMunicipio = municipio.Recnum; item.descripcionMunicipio = municipio.DescMunicipio; MunicipioGetDto municipioGetDto = _mapper.Map <MunicipioGetDto>(municipio); item.MunicipioGetDto = municipioGetDto; } } var permiteAdicionarDetalle = await _unitOfWork.AppGeneralQuotesRepository.PermiteAdicionarDetalle(item.Id); item.PermiteAdicionarDetalle = permiteAdicionarDetalle; item.AppGeneralQuotesActionSheetDto = await GetAppGeneralQuotesActionSheetDto(item.Id); ApiResponse <List <AppDetailQuotesGetDto> > listDetail = await _appDetailQuotesService.GetListAppDetailQuoteByAppGeneralQuotesId(item.Id); if (listDetail != null) { item.AppDetailQuotesGetDto = listDetail.Data; } item.FechaString = item.Fecha.ToString("dd/MM/yyyy"); } PagedList <AppGeneralQuotesGetDto> pagedResult = PagedList <AppGeneralQuotesGetDto> .Create(appGeneralQuotesGetDto, filters.PageNumber, filters.PageSize); return(pagedResult); } else { return(null); } }
public async Task <ApiResponse <List <AppIngredientsGetDto> > > GetAllFilter(AppIngredientsQueryFilter filter) { filter.PageNumber = filter.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filter.PageNumber; filter.PageSize = filter.PageSize == 0 ? _paginationOptions.DefaultPageSize : filter.PageSize; List <AppIngredientsGetDto> resultDto = new List <AppIngredientsGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppIngredientsGetDto> > response = new ApiResponse <List <AppIngredientsGetDto> >(resultDto); try { List <AppIngredients> appIngredients = await _unitOfWork.AppIngredientsRepository.GetAllFilter(filter); if (appIngredients != null) { List <AppIngredientsGetDto> appIngredientsDto = _mapper.Map <List <AppIngredientsGetDto> >(appIngredients); foreach (AppIngredientsGetDto item in appIngredientsDto) { AppUnits AppUnitsFind = await _appUnitsService.GetById(item.AppUnitId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); item.AppUnitsGetDto = appUnitsGetDto; } MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); item.PrymaryMtrMonedaDto = mtrTipoMonedaDto; } MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); item.SecundaryMtrMonedaDto = mtrTipoMonedaDto; } } response.Data = appIngredientsDto; response.Meta = metadata; return(response); } else { metadata.IsValid = true; metadata.Message = "No Data...."; response.Data = null; response.Meta = metadata; return(response); } } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = null; response.Meta = metadata; return(response); } }
public async Task <ApiResponse <AppIngredientsGetDto> > UpdateAppIngredient(AppIngredientsUpdateDto dto) { AppIngredientsGetDto resultDto = new AppIngredientsGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppIngredientsGetDto> response = new ApiResponse <AppIngredientsGetDto>(resultDto); try { var ingredient = await GetById(dto.Id); if (ingredient == null) { metadata.IsValid = false; metadata.Message = "Ingrediente No existe"; response.Data = resultDto; response.Meta = metadata; return(response); } if (dto.Code == null || dto.Code == "") { metadata.IsValid = false; metadata.Message = "Codigo Invalido"; response.Data = resultDto; response.Meta = metadata; return(response); } if (dto.Description == null || dto.Description == "") { metadata.IsValid = false; metadata.Message = "Descripcion Invalida"; response.Data = resultDto; response.Meta = metadata; return(response); } if (dto.Cost <= 0) { metadata.IsValid = false; metadata.Message = "Costo Invalido"; response.Data = resultDto; response.Meta = metadata; return(response); } AppUnits AppUnitsFind = await _appUnitsService.GetById(dto.AppUnitId); if (AppUnitsFind == null) { metadata.IsValid = false; metadata.Message = "Unidad de Medida no existe!!"; response.Data = resultDto; response.Meta = metadata; return(response); } MtrTipoMoneda MtrTipoMonedaPrymaryFind = await _mtrTipoMonedaService.GetById((long)dto.PrymaryMtrMonedaId); if (MtrTipoMonedaPrymaryFind == null) { metadata.IsValid = false; metadata.Message = "Moneda Primaria no existe!!"; response.Data = resultDto; response.Meta = metadata; return(response); } MtrTipoMoneda MtrTipoMonedaSecundaryFind = await _mtrTipoMonedaService.GetById((long)dto.SecundaryMtrMonedaId); if (MtrTipoMonedaSecundaryFind == null) { metadata.IsValid = false; metadata.Message = "Moneda Secundaria no existe!!"; response.Data = resultDto; response.Meta = metadata; return(response); } ingredient.Code = dto.Code; ingredient.Description = dto.Description; ingredient.Cost = dto.Cost; ingredient.AppUnitId = dto.AppUnitId; ingredient.PrymaryMtrMonedaId = dto.PrymaryMtrMonedaId; ingredient.SecundaryMtrMonedaId = dto.SecundaryMtrMonedaId; ingredient.UserUpdate = dto.UsuarioConectado; ingredient.UpdatedAt = DateTime.Now; var updated = await Update(ingredient); resultDto = _mapper.Map <AppIngredientsGetDto>(updated); await RecalculateRecipesByIngredient(ingredient.Id); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); resultDto.AppUnitsGetDto = appUnitsGetDto; } if (MtrTipoMonedaPrymaryFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaPrymaryFind); resultDto.PrymaryMtrMonedaDto = mtrTipoMonedaDto; } if (MtrTipoMonedaSecundaryFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaSecundaryFind); resultDto.SecundaryMtrMonedaDto = mtrTipoMonedaDto; } response.Data = resultDto; response.Meta = metadata; return(response); } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = null; response.Meta = metadata; return(response); } }
public async Task <ApiResponse <AppProductsGetDto> > GetProduct(int id) { AppProductsGetDto resultDto = new AppProductsGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppProductsGetDto> response = new ApiResponse <AppProductsGetDto>(resultDto); try { AppProducts appProductsFind = await GetById(id); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Codigo de producto no existe, verifique por favor"; response.Meta = metadata; response.Data = resultDto; return(response); } resultDto = _mapper.Map <AppProductsGetDto>(appProductsFind); AppUnits AppUnitsFind = await _appUnitsService.GetById((int)appProductsFind.AppUnitsId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); resultDto.AppUnitsGetDto = appUnitsGetDto; } AppUnitsFind = await _appUnitsService.GetById((int)appProductsFind.ProductionUnitId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); resultDto.ProductionUnitGetDto = appUnitsGetDto; } MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)appProductsFind.PrymaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); resultDto.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto; } MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)appProductsFind.SecundaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); resultDto.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto; } AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)appProductsFind.AppSubCategoryId); if (AppSubCategoryFind != null) { AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind); resultDto.AppSubCategoryGetDto = appSubCategoryGetDto; } if (resultDto.UrlImage == "" || resultDto.UrlImage == null) { resultDto.Link = _paginationOptions.UrlGetFiles + "NoImage.png"; } else { resultDto.Link = _paginationOptions.UrlGetFiles + resultDto.UrlImage; } 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); } }
public async Task <ApiResponse <List <AppProductsGetDto> > > GetAll(AppProdutsQueryFilter filters) { filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber; filters.PageSize = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize; List <AppProductsGetDto> resultDto = new List <AppProductsGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppProductsGetDto> > response = new ApiResponse <List <AppProductsGetDto> >(resultDto); try { var appProducts = await _unitOfWork.AppProductsRepository.GetAllFilter(filters); if (appProducts != null) { List <AppProductsGetDto> appProductsDto = _mapper.Map <List <AppProductsGetDto> >(appProducts); foreach (var item in appProductsDto) { if (item.UrlImage == "" || item.UrlImage == null) { item.Link = _paginationOptions.UrlGetFiles + "NoImage.png"; } else { item.Link = _paginationOptions.UrlGetFiles + item.UrlImage; } AppUnits AppUnitsFind = await _appUnitsService.GetById((int)item.AppUnitsId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); item.AppUnitsGetDto = appUnitsGetDto; } AppUnitsFind = await _appUnitsService.GetById((int)item.ProductionUnitId); if (AppUnitsFind != null) { AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind); item.ProductionUnitGetDto = appUnitsGetDto; } MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); item.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto; } MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId); if (MtrTipoMonedaFind != null) { MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind); item.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto; } AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)item.AppSubCategoryId); if (AppSubCategoryFind != null) { AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind); item.AppSubCategoryGetDto = appSubCategoryGetDto; } } response.Data = appProductsDto; response.Meta = metadata; return(response); } else { metadata.IsValid = true; metadata.Message = "No Data...."; response.Data = null; response.Meta = metadata; return(response); } } catch (Exception ex) { metadata.IsValid = false; metadata.Message = ex.InnerException.Message; response.Data = null; response.Meta = metadata; return(response); } }