public ActionResult New(AddEditProductForm model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("~/Views/Shared/AddNewPopup.cshtml", model).WithWarning("Some fields are invalid!"));
            }

            var catID = Convert.ToInt32(model.CategoryID);

            var manID = Convert.ToInt32(model.ManufacturerID);

            var product = new Product(model.Name, _context.Categories.FirstOrDefault(c => c.ID == catID),
                                      _context.Manufacturers.FirstOrDefault(m => m.ID == manID),
                                      model.ShortDescription, model.FullDescription, model.SKU, model.Image);

            product.Components     = model.Components;
            product.ProductMeasure = _context.Measuries.FirstOrDefault(m => m.Name == model.ContentUnitMeasureName);
            product.DisplayOrder   = model.DisplayOrder;
            product.IsKosher       = model.IsKosher;
            //product.IsVegan = model.IsVegan;
            product.KosherType      = model.KosherType;
            product.UnitsPerPackage = model.UnitsPerPackage;

            _context.Products.Add(product);

            _context.SaveChanges();

            return(Json(new { success = true }));
        }
        public ActionResult Edit(AddEditProductForm model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("~/Views/Shared/EditPopup.cshtml", model));
            }

            var product = _context.Products.SingleOrDefault(i => i.ID == model.ID);

            if (product == null)
            {
                return(JsonError("Cannot find the product specified."));
            }

            product.Components      = model.Components;
            product.ProductMeasure  = _context.Measuries.FirstOrDefault(m => m.Name == model.ContentUnitMeasureName);
            product.DisplayOrder    = model.DisplayOrder;
            product.IsKosher        = model.IsKosher;
            product.KosherType      = model.KosherType;
            product.UnitsPerPackage = model.UnitsPerPackage;

            _context.SaveChanges();

            return(Json(new { success = true }));
        }
 private void DGVProductsList_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 6)
     {
         AddEditProductForm addEdit = new AddEditProductForm((ProductDTO)dGVProductsList.CurrentRow.Tag, this);
         addEdit.Show();
     }
     if (e.ColumnIndex == 7)
     {
         ProductDTO product = (ProductDTO)dGVProductsList.CurrentRow.Tag;
         if (MessageBox.Show("Удалить " + product.Name + " ?", "Подтверждение удаления", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             MainForm.DB.Products.Delete(product.Id);
             MainForm.DB.Save();
             LoggingService.AddLog("Удаление продукта: " + product.ToString());
             ReloadData();
         }
     }
 }
        private void ButAddProduct_Click(object sender, EventArgs e)
        {
            AddEditProductForm addForm = new AddEditProductForm(this);

            addForm.Show();
        }