public async Task <AppIngredients> Insert(AppIngredients appIngredients) { await _unitOfWork.AppIngredientsRepository.Add(appIngredients); await _unitOfWork.SaveChangesAsync(); return(appIngredients); }
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 <AppIngredients> Update(AppIngredients appIngredients) { AppIngredients AppIngredientsFind = await GetById(appIngredients.Id); if (AppIngredientsFind == null) { throw new Exception("Documento No existe"); } _unitOfWork.AppIngredientsRepository.Update(appIngredients); await _unitOfWork.SaveChangesAsync(); return(await GetById(appIngredients.Id)); }
public async Task UpdateVariableSearchByProduct(int productId) { var product = await _unitOfWork.AppProductsRepository.GetById(productId); if (product != null) { var searchText = ""; var recipe = await GetAllRecipesByProductId(productId); if (recipe != null) { foreach (AppRecipes item in recipe.Where(x => x.IncludeInSearch == true).ToList()) { var value = ""; AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)item.AppIngredientsId); if (appIngredientsFind != null) { value = appIngredientsFind.Description.Trim(); } else { AppVariables appVariablesFind = await _appVariablesService.GetById((int)item.AppVariableId); if (appVariablesFind != null) { value = appVariablesFind.Code.Trim(); } } await _appVariableSearchService.CreateVariableSearchTextBySubcategoryVariableSearchTex((int)product.AppSubCategoryId, (int)item.AppVariableId, value); searchText = searchText + item.AppVariableId.ToString().Trim() + value.Trim(); } product.VariablesSearchText = searchText; await _appProductsService.Update(product); } } }
public async Task <ApiResponse <List <AppRecipesGetDto> > > UpdateAppRecipes(AppRecipesUpdateDto dto) { List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppRecipesGetDto> > response = new ApiResponse <List <AppRecipesGetDto> >(resultDto); try { var recipe = await GetById(dto.Id); if (recipe == null) { metadata.IsValid = false; metadata.Message = "Receta no existe!!"; response.Data = null; response.Meta = metadata; return(response); } AppProducts appProductsFind = await _appProductsService.GetById((int)dto.AppproductsId); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Producto no existe!!"; response.Data = null; response.Meta = metadata; return(response); } AppVariables appVariablesFind = await _appVariablesService.GetById((int)dto.AppVariableId); if (appVariablesFind == null) { metadata.IsValid = false; metadata.Message = "Variable no existe!!"; response.Data = null; response.Meta = metadata; return(response); } if (dto.Formula.Length > 0) { dto.AppIngredientsId = null; } recipe.Code = appVariablesFind.Code; recipe.Description = appVariablesFind.Description; recipe.Quantity = dto.Quantity; recipe.SumValue = dto.SumValue; recipe.OrderCalculate = dto.OrderCalculate; recipe.IncludeInSearch = dto.IncludeInSearch; recipe.AfectaCosto = dto.AfectaCosto; recipe.Secuencia = dto.Secuencia; recipe.AppIngredientsId = dto.AppIngredientsId; if (dto.AppIngredientsId != null) { AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)dto.AppIngredientsId); if (appIngredientsFind == null) { metadata.IsValid = false; metadata.Message = "Ingrediente no existe!!"; response.Data = null; response.Meta = metadata; return(response); } else { if (dto.AfectaCosto == true) { recipe.TotalCost = appIngredientsFind.Cost * recipe.Quantity; } else { recipe.TotalCost = 0; } } } else { if (dto.Formula == "" || dto.Formula == null) { metadata.IsValid = false; metadata.Message = "Debe Indicar Una formula o seleccionar un ingrediente!!"; response.Data = null; response.Meta = metadata; return(response); } recipe.TotalCost = 0; recipe.Formula = dto.Formula; recipe.FormulaValue = ""; } var updated = await Update(recipe); await UpdateVariableSearchByProduct((int)dto.AppproductsId); var listRecipeCalculate = await CalulateRecipeByProduct((int)dto.AppproductsId); metadata.IsValid = true; metadata.Message = "Receta actualizada!"; response.Data = listRecipeCalculate; 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 <List <AppRecipesGetDto> > > CreateAppRecipes(AppRecipesCreateDto dto) { List <AppRecipesGetDto> resultDto = new List <AppRecipesGetDto>(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <List <AppRecipesGetDto> > response = new ApiResponse <List <AppRecipesGetDto> >(resultDto); try { AppRecipes appRecipes = _mapper.Map <AppRecipes>(dto); //var recipeByProductVariable = await GetRecipesByProductIdVariableId((int)dto.AppproductsId, (int)dto.AppVariableId); //if (recipeByProductVariable != null) //{ // metadata.IsValid = false; // metadata.Message = "Variable ya existe en este producto!!"; // response.Data = null; // response.Meta = metadata; // return response; //} AppProducts appProductsFind = await _appProductsService.GetById((int)dto.AppproductsId); if (appProductsFind == null) { metadata.IsValid = false; metadata.Message = "Producto no existe!!"; response.Data = null; response.Meta = metadata; return(response); } AppVariables appVariablesFind = await _appVariablesService.GetById((int)dto.AppVariableId); if (appVariablesFind == null) { metadata.IsValid = false; metadata.Message = "Variable no existe!!"; response.Data = null; response.Meta = metadata; return(response); } appRecipes.Code = appVariablesFind.Code; appRecipes.Description = appVariablesFind.Description; appRecipes.Quantity = dto.Quantity; appRecipes.SumValue = dto.SumValue; appRecipes.OrderCalculate = dto.OrderCalculate; appRecipes.IncludeInSearch = dto.IncludeInSearch; appRecipes.AfectaCosto = dto.AfectaCosto; appRecipes.Secuencia = dto.Secuencia; if (dto.AppIngredientsId != null) { AppIngredients appIngredientsFind = await _unitOfWork.AppIngredientsRepository.GetById((int)dto.AppIngredientsId); if (appIngredientsFind == null) { metadata.IsValid = false; metadata.Message = "Ingrediente no existe!!"; response.Data = null; response.Meta = metadata; return(response); } else { if (dto.AfectaCosto == true) { appRecipes.TotalCost = appIngredientsFind.Cost * appRecipes.Quantity; } else { appRecipes.TotalCost = 0; } } } else { if (dto.Formula == "" || dto.Formula == null) { metadata.IsValid = false; metadata.Message = "Debe Indicar Una formula o seleccionar un ingrediente!!"; response.Data = null; response.Meta = metadata; return(response); } appRecipes.TotalCost = 0; appRecipes.Formula = dto.Formula; appRecipes.FormulaValue = ""; } var inserted = await Insert(appRecipes); await UpdateVariableSearchByProduct((int)dto.AppproductsId); var listRecipeCalculate = await CalulateRecipeByProduct((int)dto.AppproductsId); response.Data = listRecipeCalculate; 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 <bool> > DeleteAppIngredients(AppIngredientsDeleteDto dto) { bool resultDto = true; Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <bool> response = new ApiResponse <bool>(resultDto); try { AppIngredients appIngredients = await GetById(dto.Id); if (appIngredients == null) { metadata.IsValid = false; metadata.Message = "Ingrediente No existe!!!"; response.Meta = metadata; response.Data = resultDto; return(response); } AppRecipes recipes = await _unitOfWork.AppRecipesRepository.GetRecipesByIdIngredients(dto.Id); if (recipes != null) { metadata.IsValid = false; metadata.Message = "Ingrediente existe en la formulacion!!!"; response.Meta = metadata; response.Data = resultDto; return(response); } resultDto = await Delete(dto.Id); metadata.IsValid = true; metadata.Message = $"Ingrediente Eliminada Satisfactoriamente!"; 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 <AppIngredientsGetDto> > CreateAppIngredient(AppIngredientsCreateDto dto) { AppIngredientsGetDto resultDto = new AppIngredientsGetDto(); Metadata metadata = new Metadata { IsValid = true, Message = "" }; ApiResponse <AppIngredientsGetDto> response = new ApiResponse <AppIngredientsGetDto>(resultDto); try { AppIngredients appIngredients = _mapper.Map <AppIngredients>(dto); 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); } appIngredients.UserCreate = dto.UsuarioConectado; appIngredients.UserUpdate = dto.UsuarioConectado; appIngredients.CreatedAt = DateTime.Now; appIngredients.UpdatedAt = DateTime.Now; var inserted = await Insert(appIngredients); resultDto = _mapper.Map <AppIngredientsGetDto>(inserted); 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 Delete(int id) { AppIngredients entity = await GetById(id); _context.AppIngredients.Remove(entity); }
public void Update(AppIngredients entity) { _context.AppIngredients.Update(entity); }
public async Task Add(AppIngredients entity) { await _context.AppIngredients.AddAsync(entity); }