Beispiel #1
0
        public async Task <IActionResult> UpdateAppProducts(AppProductsUpdateDto appProductsUpdateDto)
        {
            var response = await _appProductsService.UpdateProducts(appProductsUpdateDto);

            return(Ok(response));
        }
Beispiel #2
0
        public async Task <ApiResponse <AppProductsGetDto> > UpdateProducts(AppProductsUpdateDto appProductsUpdateDto)
        {
            AppProductsGetDto resultDto = new AppProductsGetDto();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };

            ApiResponse <AppProductsGetDto> response = new ApiResponse <AppProductsGetDto>(resultDto);

            try
            {
                AppProducts appProductsFind = await GetById(appProductsUpdateDto.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);
                }


                if (appProductsUpdateDto.ExternalCode == "")
                {
                    metadata.IsValid = false;
                    metadata.Message = "Codigo Externo no es valido";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                AppUnits appUnitsFind = await _appUnitsService.GetById((int)appProductsUpdateDto.AppUnitsId);

                if (appUnitsFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Unidad venta del Producto No existe";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                appUnitsFind = await _appUnitsService.GetById((int)appProductsUpdateDto.ProductionUnitId);

                if (appUnitsFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Unidad Produccion del Producto No existe";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }



                MtrTipoMoneda mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById((long)appProductsUpdateDto.PrymaryMtrMonedaId);

                if (mtrTipoMonedaFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Moneda Primaria No Existe!!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                mtrTipoMonedaFind = await _unitOfWork.MtrTipoMonedaRepository.GetById((long)appProductsUpdateDto.SecundaryMtrMonedaId);

                if (mtrTipoMonedaFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Moneda Secundaria No Existe!!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }


                AppSubCategory appSubCategory = await _unitOfWork.AppSubCategoryRepository.GetById((int)appProductsUpdateDto.AppSubCategoryId);

                if (appSubCategory == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Subcategoria No Existe!!! ";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }


                appProductsFind.ProductionUnitId     = appProductsUpdateDto.ProductionUnitId;
                appProductsFind.AppUnitsId           = appProductsUpdateDto.AppUnitsId;
                appProductsFind.AppSubCategoryId     = appProductsUpdateDto.AppSubCategoryId;
                appProductsFind.PrymaryMtrMonedaId   = appProductsUpdateDto.PrymaryMtrMonedaId;
                appProductsFind.SecundaryMtrMonedaId = appProductsUpdateDto.SecundaryMtrMonedaId;
                appProductsFind.UnitPrice            = appProductsUpdateDto.UnitPrice;
                appProductsFind.Description1         = appProductsUpdateDto.Description1;
                appProductsFind.Description2         = appProductsUpdateDto.Description2;
                appProductsFind.ExternalCode         = appProductsUpdateDto.ExternalCode;


                appProductsFind.UserUpdate = appProductsUpdateDto.UsuarioConectado;
                appProductsFind.UpdatedAt  = DateTime.Now;


                AppProducts appProductsUpdated = await Update(appProductsFind);



                if (appProductsUpdated != null)
                {
                    resultDto = _mapper.Map <AppProductsGetDto>(appProductsUpdated);

                    AppUnits AppUnitsFind = await _appUnitsService.GetById((int)appProductsUpdated.AppUnitsId);

                    if (AppUnitsFind != null)
                    {
                        AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                        resultDto.AppUnitsGetDto = appUnitsGetDto;
                    }

                    if (resultDto.UrlImage == "" || resultDto.UrlImage == null)
                    {
                        resultDto.Link = _paginationOptions.UrlGetFiles + "NoImage.png";
                    }
                    else
                    {
                        resultDto.Link = _paginationOptions.UrlGetFiles + resultDto.UrlImage;
                    }


                    metadata.IsValid = true;
                    metadata.Message = $"Producto: {resultDto.Code} Actualizado 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);
            }
        }