public async Task <List <AppRecipesGetDto> > GetRecipesGetDtoByProductId(AppRecipesQueryFilter filter) { List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>(); var recipes = await GetAllRecipesByProductId(filter.AppproductsId); if (recipes != null) { if (filter.SearchText != "" && filter.SearchText != null) { recipes = recipes.Where(x => x.Description.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Code.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower()) || x.Formula.Trim().ToLower().Contains(filter.SearchText.Trim().ToLower())).ToList(); } List <AppRecipesGetDto> recipesDto = _mapper.Map <List <AppRecipesGetDto> >(recipes); foreach (var item in recipesDto) { AppProducts appProductsFind = await _appProductsService.GetById((int)item.AppproductsId); if (appProductsFind != null) { AppProductsGetDto appProductsGetDto = _mapper.Map <AppProductsGetDto>(appProductsFind); item.AppProductsGetDto = appProductsGetDto; } AppVariables appVariablesFind = await _appVariablesService.GetById((int)item.AppVariableId); if (appVariablesFind != null) { AppVariablesGetDto appVariablesGetDto = _mapper.Map <AppVariablesGetDto>(appVariablesFind); item.AppVariablesGetDto = appVariablesGetDto; } if (item.AppIngredientsId != null) { AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)item.AppIngredientsId); if (appIngredientsFind != null) { AppIngredientsGetDto appIngredientsGetDto = _mapper.Map <AppIngredientsGetDto>(appIngredientsFind); item.AppIngredientsGetDto = appIngredientsGetDto; } } } resultDto = recipesDto; } return(resultDto); }
public async Task <ApiResponse <AppProductsGetDto> > UpdateImageAppProduct(AppproductImageDto dto) { AppProductsGetDto resultDto = new AppProductsGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppProductsGetDto> response = new ApiResponse <AppProductsGetDto>(resultDto); var product = await _appProductsService.GetById(dto.Id); if (product == null) { metadata.IsValid = false; metadata.Message = "Codigo de producto no existe, verifique por favor"; response.Meta = metadata; response.Data = resultDto; return(response); } var NombreArchivo = $@"Producto_{product.Code}_{DateTime.Now.Ticks}" + ".png"; var FechaCreacion = DateTime.Now; var Ruta = _paginationOptions.FolderDocumentation + "\\"; // //CREA EL ARCHIVO DE IMAGEN //Convert Base64 Encoded string to Byte Array. string base64 = dto.Data; byte[] imageBytes = Convert.FromBase64String(base64); //Ruta y nombre de la imagen var imageFullName = Ruta + NombreArchivo; //creo el fichero await System.IO.File.WriteAllBytesAsync(imageFullName, imageBytes); product.UrlImage = NombreArchivo; var productUpdated = await _appProductsService.Update(product); var result = await _appProductsService.GetProduct(product.Id); resultDto = result.Data; metadata.IsValid = true; metadata.Message = "Imagen de producto Actualizada"; response.Meta = metadata; response.Data = resultDto; return(response); }