コード例 #1
0
        public async Task <IActionResult> Edit(IngredientEditModel ingredientModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(ingredientModel));
            }

            bool?isSuccessfullyEdited = await this.ingredients.Edit(ingredientModel.Id, ingredientModel.Name, ingredientModel.MinStockQuantityThreshold);

            if (isSuccessfullyEdited == null)
            {
                return(this.NotFound());
            }

            if (isSuccessfullyEdited.Value)
            {
                this.TempData[SuccessMessageKey] = string.Format(CookConstants.IngredientEditionSuccessMessage, ingredientModel.Name);
            }
            else
            {
                this.ModelState.AddModelError("Name", CookConstants.IngredientExistsErrorMessage);
                return(this.View(ingredientModel));
            }

            return(this.RedirectToAction(nameof(IngredientsController.Index)));
        }
コード例 #2
0
 public IngredientController(IGetIngredient getIngredient, ICreateIngredient createIngredient, IUpdateIngredient updateIngredient, IIngredientService ingredientService, IngredientEditModel ingredientEditModel)
 {
     this._createIngredient   = createIngredient;
     this._getIngredient      = getIngredient;
     this._ingredientService  = ingredientService;
     this._updateIngredient   = updateIngredient;
     this.IngredientEditModel = ingredientEditModel;
 }
コード例 #3
0
        public ActionResult Edit(IngredientEditModel ingredientEditModel)
        {
            UpdateIngredient updateIngredient = new UpdateIngredient();
            string           type             = "Update";

            sqlCommand = new SqlCommand();

            sqlCommand = updateIngredient.UpdateIngredientData(ingredientEditModel, type);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id)
        {
            IngredientEditModel ingredient = await this.ingredients.GetIngredientToEdit(id);

            if (ingredient == null)
            {
                return(this.NotFound());
            }

            return(this.View(ingredient));
        }
コード例 #5
0
 public ActionResult Delete(IngredientEditModel ingredientEditModel)
 {
     sqlCommand = new SqlCommand();
     try
     {
         string type = "Delete";
         sqlCommand = this._updateIngredient.UpdateIngredientData(ingredientEditModel, type);
     }
     catch (Exception ex)
     {
         ViewBag.FileStatus = ex;
     }
     return(RedirectToAction("Index", "Home"));
 }
コード例 #6
0
        private void AddIngredient(IngredientEditModel ingr,
            List<RecipeIngredient> ingredients,
            Recipe recipe)
        {
            if(!this.dbContext
                .Measurements
                .Any(m => m.Name == ingr.Measurement))
            {
                this.dbContext
                    .Measurements
                    .Add(new Measurement
                    {
                        Name = ingr.Measurement
                    });

                this.dbContext.SaveChanges();
            }

            var measurement = this.dbContext
                    .Measurements
                    .FirstOrDefault(m => m.Name == ingr.Measurement);

            var quantity = ingr.Quantity;

            if (!this.dbContext.Ingredients.Any(i => i.Name == ingr.Name))
            {
                this.dbContext.Ingredients.Add(new Ingredient
                {
                    Name = ingr.Name
                });

                this.dbContext.SaveChanges();
            }

            var ingredient = this.dbContext
                .Ingredients
                .FirstOrDefault(i => i.Name == ingr.Name);

            ingredients.Add(new RecipeIngredient
            {
                Measurement = measurement,
                Quantity = quantity,
                Ingredient = ingredient,
                Recipe = recipe
            });
        
        }
コード例 #7
0
 // GET: Ingredient/Delete/5
 public ActionResult Delete(int id)
 {
     this.IngredientEditModel = this._ingredientService.FillData(id);
     if (this.IngredientEditModel.Carbohydrate != null &&
         this.IngredientEditModel.DescriptionOne != null &&
         this.IngredientEditModel.DescriptionSec != null &&
         this.IngredientEditModel.Fat != null &&
         this.IngredientEditModel.OrderTitle != null &&
         this.IngredientEditModel.Protein != null &&
         this.IngredientEditModel.Title != null &&
         this.IngredientEditModel.TitleOne != null)
     {
         return(View(this.IngredientEditModel));
     }
     else
     {
         return(PartialView("_404"));
     }
 }
コード例 #8
0
 public SqlCommand CreateIngredientData(IngredientEditModel ingredientEditModel)
 {
     using (sqlConnection = new SqlConnection(SqlConn.ConnectionString))
     {
         sqlConnection.Open();
         sqlCommand             = new SqlCommand("SpMasterIngredientsDetail", sqlConnection);
         sqlCommand.CommandType = CommandType.StoredProcedure;
         sqlCommand.Parameters.AddWithValue("@StatementType", "Insert");
         sqlCommand.Parameters.AddWithValue("@IngredientTitle", ingredientEditModel.Title);
         sqlCommand.Parameters.AddWithValue("@IngredientTitleOne", ingredientEditModel.TitleOne);
         sqlCommand.Parameters.AddWithValue("@IngredientDesc", ingredientEditModel.DescriptionOne);
         sqlCommand.Parameters.AddWithValue("@IngredientDescSec", ingredientEditModel.DescriptionSec);
         sqlCommand.Parameters.AddWithValue("@IngredientProtein", ingredientEditModel.Protein);
         sqlCommand.Parameters.AddWithValue("@IngredientCarbohydrate", ingredientEditModel.Carbohydrate);
         sqlCommand.Parameters.AddWithValue("@IngredientFat", ingredientEditModel.Fat);
         sqlCommand.Parameters.AddWithValue("@IngredientOrderTitle", ingredientEditModel.OrderTitle);
         sqlCommand.Parameters.AddWithValue("@IsActive", "1");
         sqlCommand.ExecuteNonQuery();
     }
     return(sqlCommand);
 }
コード例 #9
0
 public ActionResult Create(IngredientEditModel ingredientEditModel, HttpPostedFileBase Image)
 {
     sqlCommand = new SqlCommand();
     sqlCommand = this._createIngredient.CreateIngredientData(ingredientEditModel);
     return(RedirectToAction("Index", "Home"));
 }