コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task <ActionResult <Model.Ingredient> > PostIngredients(Model.Ingredient ingredients)
        {
            _context.Ingredients.Add(ingredients);
            await _context.SaveChangesAsync();

            return(null);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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);
 }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
 public CheckIngredientCommand(Model.Ingredient data)
 {
     _data = data;
 }
コード例 #7
0
ファイル: IngredientVM.cs プロジェクト: Linksonder/Prog5
 public IngredientVM()
 {
     this.ingredient = new Model.Ingredient();
 }
コード例 #8
0
ファイル: IngredientVM.cs プロジェクト: Linksonder/Prog5
 public IngredientVM(Model.Ingredient ingredient)
 {
     // TODO: Complete member initialization
     this.ingredient = ingredient;
 }
コード例 #9
0
        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);
        }
コード例 #10
0
 public void Delete(Model.Ingredient recipe)
 {
     _dbContext.Ingredients.Remove(recipe);
     _dbContext.SaveChanges();
 }
コード例 #11
0
ファイル: IngredientVM.cs プロジェクト: Linksonder/Prog5
 public IngredientVM()
 {
     this.ingredient = new Model.Ingredient();
 }
コード例 #12
0
ファイル: IngredientVM.cs プロジェクト: Linksonder/Prog5
 public IngredientVM(Model.Ingredient ingredient)
 {
     // TODO: Complete member initialization
     this.ingredient = ingredient;
 }
コード例 #13
0
 public UpdateIngredientCommand(Model.Ingredient data)
 {
     _data = data;
 }
コード例 #14
0
 public InsertIngredientCommand(Model.Ingredient data)
 {
     _data = data;
 }