public static Product_Type InsertProductType(Product_Type pro)
        {
            db.Product_Types.Add(pro);
            db.SaveChanges();

            return(pro);
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Product_TypeId,type")] Product_Type product_Type)
        {
            if (id != product_Type.Product_TypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product_Type);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Product_TypeExists(product_Type.Product_TypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product_Type));
        }
 private void AddButton_Click(object sender, RoutedEventArgs e)
 {
     using (MyDBContext db = new MyDBContext())
     {
         if (!String.IsNullOrWhiteSpace(NameBox.Text) &&
             !String.IsNullOrWhiteSpace(DescrBox.Text))
         {
             Product_Type product_Type = new Product_Type
             {
                 ID          = db.Dish_Types.Count() + 1,
                 Name        = NameBox.Text,
                 Description = DescrBox.Text
             };
             if (EditID == -1)
             {
                 db.Product_Types.Add(product_Type);
             }
             else
             {
                 var result = db.Product_Types.Find(EditID);
                 result.Name        = NameBox.Text;
                 result.Description = DescrBox.Text;
             }
         }
         else
         {
             MessageBox.Show("Заполнены не все поля");
         }
         db.SaveChanges();
         this.Close();
     }
 }
Esempio n. 4
0
        public IHttpActionResult PutProduct_Type(int id, Product_Type product_Type)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product_Type.Product_Type_ID)
            {
                return(BadRequest());
            }

            db.Entry(product_Type).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Product_TypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            models.ProductTypeModel model = new models.ProductTypeModel();
            Product_Type            pt    = CreateProduct_Type();

            lblResult.Text = model.InsertProductType(pt);
        }
Esempio n. 6
0
        private void btnDeletePT_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Would you like to delete this Product Type?", "Delete Product Type", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    Product_Type prodT2 = new Product_Type();
                    prodT2 = db.Product_Type.Find(tempID);

                    db.Product_Type.Remove(prodT2);
                    db.SaveChanges();

                    int    prodType       = prodT2.Product_Type_ID;
                    string prodType_Value = Convert.ToString(prodT2);
                    MessageBox.Show("Product Type Successfully Deleted");
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Error: Product Type was not deleted, currently in use");
                }
            }
        }
Esempio n. 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorLabel.Visible = false;
            if (Session["email"] != null)
            {
                User u = UserController.GetUser(Session["email"].ToString());

                if (u.RoleID == 1)
                {
                    if (Request.QueryString["protypeid"] != null)
                    {
                        protypeid = int.Parse(Request.QueryString["protypeid"]);
                        pro       = ProductTypeController.GetProductType(protypeid);
                        if (!IsPostBack)
                        {
                            proTypeText.Text = pro.Name.ToString();
                            descTxt.Text     = pro.Description.ToString();
                        }
                    }
                    else
                    {
                        Response.Redirect("ViewProductType.aspx");
                    }
                }
                else
                {
                    CantAccessView();
                }
            }
            else
            {
                CantAccessView();
            }
        }
        public static Product_Type DeleteProductType(int ID)
        {
            Product_Type pro = GetProductType(ID);

            db.Product_Types.Remove(pro);
            db.SaveChanges();
            return(pro);
        }
Esempio n. 9
0
        public ActionResult DeleteConfirmed(int id)
        {
            Product_Type product_Type = db.Product_Type.Find(id);

            db.Product_Type.Remove(product_Type);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 10
0
        private Product_Type CreateProduct_Type()
        {
            Product_Type p = new Product_Type();

            p.Type = txtName.Text;

            return(p);
        }
        public static Product_Type UpdateProductType(int id, string name, string desc)
        {
            Product_Type pro = GetProductType(id);

            pro.Name        = name;
            pro.Description = desc;
            db.SaveChanges();
            return(pro);
        }
Esempio n. 12
0
        public ActionResult Product_Type_Delete(int?id, Product_Type p)
        {
            p = db.Product_Type.Find(id);

            db.Product_Type.Remove(p);

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public static Product_Type InsertProductType(string name, string desc)
        {
            Product_Type pro = new Product_Type()
            {
                Name        = name,
                Description = desc
            };

            return(pro);
        }
Esempio n. 14
0
 public ActionResult Edit([Bind(Include = "Product_TypeID,Name")] Product_Type product_Type)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product_Type).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product_Type));
 }
Esempio n. 15
0
        public ActionResult Create([Bind(Include = "Product_TypeID,Name")] Product_Type product_Type)
        {
            if (ModelState.IsValid)
            {
                db.Product_Type.Add(product_Type);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product_Type));
        }
Esempio n. 16
0
        public static Response InsertProductType(string name, string desc)
        {
            if (ProductTypeRepositories.GetProductType(name) == null)
            {
                Product_Type pro = ProductTypeFactories.InsertProductType(name, desc);
                ProductTypeRepositories.InsertProductType(pro);
                return(new Response(true));
            }

            return(new Response(false, "The product type must be unique"));
        }
Esempio n. 17
0
        public IHttpActionResult GetProduct_Type(int id)
        {
            Product_Type product_Type = db.Product_Type.Find(id);

            if (product_Type == null)
            {
                return(NotFound());
            }

            return(Ok(product_Type));
        }
Esempio n. 18
0
        public async Task <IActionResult> Create([Bind("Product_TypeId,type")] Product_Type product_Type)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product_Type);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product_Type));
        }
Esempio n. 19
0
        public ActionResult Product_Type_Edit(int?id)
        {
            Product_Type p = db.Product_Type.Find(id);

            if (p == null)
            {
                return(HttpNotFound());
            }

            return(View(p));
        }
        public IHttpActionResult GetProduct_Type(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;
            Product_Type product_Type = db.Product_Type.Find(id);

            if (product_Type == null)
            {
                return(NotFound());
            }

            return(Ok(product_Type));
        }
Esempio n. 21
0
        public IHttpActionResult PostProduct_Type(Product_Type product_Type)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Product_Type.Add(product_Type);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = product_Type.Product_Type_ID }, product_Type));
        }
Esempio n. 22
0
        public ActionResult Product_Type_Edit(Product_Type p)
        {
            if (ModelState.IsValid)
            {
                db.Entry(p).State = EntityState.Modified;

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(p));
        }
Esempio n. 23
0
        public static Response UpdateProductType(int protypeid, string name, string desc)
        {
            Product_Type pro = ProductTypeRepositories.GetProductType(protypeid);

            if (pro.Name == name || ProductTypeRepositories.GetProductType(name) == null)
            {
                ProductTypeRepositories.UpdateProductType(protypeid, name, desc);
                return(new Response(true));
            }


            return(new Response(false, "Product Type must be unique"));
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     using (MyDBContext db = new MyDBContext())
     {
         Product_Type EditProduct_Type = db.Product_Types.Find(EditID);
         if (EditID != -1)
         {
             AddButton.Content = "Сохранить";
             NameBox.Text      = EditProduct_Type.Name;
             DescrBox.Text     = EditProduct_Type.Description;
         }
     }
 }
        public IHttpActionResult PostProduct_Type(Product_Type product_Type)
        {
            db.Configuration.ProxyCreationEnabled = false;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Product_Type.Add(product_Type);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = product_Type.Prod_ID }, product_Type));
        }
Esempio n. 26
0
 public string AddProduct_Type(string title)
 {
     try
     {
         Product_Type product_Type = new Product_Type
         {
             Title = title
         };
         Product_Types.Add(product_Type);
         SaveChanges();
         return("Запись успешно добавлена");
     }
     catch (Exception ex) { return(ex.Message); }
 }
Esempio n. 27
0
        public IHttpActionResult DeleteProduct_Type(int id)
        {
            Product_Type product_Type = db.Product_Type.Find(id);

            if (product_Type == null)
            {
                return(NotFound());
            }

            db.Product_Type.Remove(product_Type);
            db.SaveChanges();

            return(Ok(product_Type));
        }
Esempio n. 28
0
        public IHttpActionResult upload([FromBody] dynamic file)
        {
            db.Configuration.ProxyCreationEnabled = false;

            string upload = file.file;

            Product_Type product_Type = new Product_Type();

            product_Type.ImageString = upload;
            db.Product_Type.Add(product_Type);
            db.SaveChanges();

            return(Ok(product_Type));
        }
Esempio n. 29
0
        // GET: Product_Type/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product_Type product_Type = db.Product_Type.Find(id);

            if (product_Type == null)
            {
                return(HttpNotFound());
            }
            return(View(product_Type));
        }
Esempio n. 30
0
        public string InsertProductType(Product_Type productType)
        {
            try
            {
                ShopdbEntities3 db = new ShopdbEntities3();
                db.Product_Type.Add(productType);
                db.SaveChanges();

                return(productType.Type + " was succesfully inserted");
            }
            catch (Exception e)
            {
                return("Error:" + e);
            }
        }