public async Task <IActionResult> PutIngredients(int id, Model.Ingredient ingredients) { if (id != ingredients.Id) { return(null); } _context.Entry(ingredients).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await IngredientsExists(id)) { return(null); } else { throw; } } return(null); }
public async Task <ActionResult <Model.Ingredient> > PostIngredients(Model.Ingredient ingredients) { _context.Ingredients.Add(ingredients); await _context.SaveChangesAsync(); return(null); }
public static void UpdateIngredient(Model.Ingredient ingredient) { string query = "BEGIN " + "ingredient_pkg.update_ingredient(" + ingredient.Id + ", '" + ingredient.Name + "', '" + ingredient.Description + "', " + ingredient.Unit_Id + ", " + ingredient.Unit_Cost + ", " + ingredient.Amount + "); " + "END;"; DB_Handler.ExecuteQuery(query); }
public static Model.Ingredient RowToEntity(DataRow row) { Model.Ingredient ingredient = new Model.Ingredient { Name = row["Name"].ToString(), Description = row["Description"].ToString(), Unit_Cost = Int32.Parse(row["Unit_Cost"].ToString()), Amount = Double.Parse(row["Amount"].ToString()), Id = Int32.Parse(row["Id"].ToString()), Unit_Id = Int32.Parse(row["Unit_Id"].ToString()) }; return(ingredient); }
public void AddIngredient(Model.Ingredient ingredient) { //check that it's not already in DB var query = from Ingredient in _dbContext.Ingredients where ingredient.Name == Ingredient.Name && ingredient.IngredientType == Ingredient.IngredientType select Ingredient; if (query.ToList <Ingredient>().Count == 0) { _dbContext.Ingredients.Add(ingredient); _dbContext.SaveChanges(); } }
public CheckIngredientCommand(Model.Ingredient data) { _data = data; }
public IngredientVM() { this.ingredient = new Model.Ingredient(); }
public IngredientVM(Model.Ingredient ingredient) { // TODO: Complete member initialization this.ingredient = ingredient; }
public async Task <Unit> Invoke(IUnitOfWork uow) { var dbContext = DbContext.From(uow); uow.BeginTransaction(); foreach (var from in _ingredients) { var ingredient = new Model.Ingredient() { Name = from.Name, Brand = from.Brand, RiskCategory = from.RiskCategory, Status = from.Status.HasValue ? from.Status.Value : IngredientStatus.Unverified, Supplier = new Supplier() { Name = from.SupplierName }, CertifyingBody = new CertifyingBody() { Name = from.CertifyingBodyName } }; var hasIngredient = await dbContext.Ingredient.CheckIngredient(ingredient); if (hasIngredient) { if (!string.IsNullOrEmpty(ingredient.CertifyingBody?.Name)) { var certificateBody = await dbContext.CertifyingBody .GetCertifyingBodyByName(ingredient.CertifyingBody?.Name); if (certificateBody == null) { var certifyingBodyID = await dbContext.CertifyingBody .InsertCertifyingBody(ingredient.CertifyingBody); ingredient.CertifyingBodyID = certifyingBodyID; } else { ingredient.CertifyingBodyID = certificateBody?.ID; } } if (!string.IsNullOrEmpty(ingredient.Supplier?.Name)) { var supplier = await dbContext.Supplier .GetSupplierByName(ingredient.Supplier?.Name); if (supplier == null) { var supplierID = await dbContext.Supplier .InsertSupplier(ingredient.Supplier); ingredient.SupplierID = supplierID; } else { ingredient.SupplierID = supplier?.ID; } } var result = await dbContext.Ingredient.InsertIngredient(ingredient); if (result == 0) { var logText = await dbContext.Translation .GetTranslation(Locale.EN, "ValidateIngredient"); throw new BadRequestException(logText); } } } uow.Commit(); return(Unit.Default); }
public void Delete(Model.Ingredient recipe) { _dbContext.Ingredients.Remove(recipe); _dbContext.SaveChanges(); }
public UpdateIngredientCommand(Model.Ingredient data) { _data = data; }
public InsertIngredientCommand(Model.Ingredient data) { _data = data; }