Пример #1
0
        public IHttpActionResult PutProducts_StoreProduct(int id, Products_StoreProduct products_StoreProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != products_StoreProduct.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public string InsertDb(tbl_products args)
        {
            string result = "";

            if (ValidateExist(args, null))
            {
                tbl_products product = new tbl_products
                {
                    number      = args.number,
                    title       = args.title,
                    price       = args.price,
                    last_update = DateTime.Now
                };
                db.tbl_products.Add(product);
                db.SaveChanges();

                InsertProductCategories(product.id_product, args.ids_product_categories);
                result = "Producto guardado exitosamente!";
            }
            else
            {
                result = "El producto ya existe en la base de datos";
            }
            return(result);
        }
Пример #3
0
 public ActionResult CreateUser([Bind(Include = "Id,Ime,Prezime,Email,AdresaDostave,Kontakt,Napomena")] Korisnici korisnici)
 {
     if (ModelState.IsValid)
     {
         db.Korisnicis.Add(korisnici);
         db.SaveChanges();
         return(RedirectToAction("CreateOrder", korisnici));
     }
     return(View(korisnici));
 }
Пример #4
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            return(View(product));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "ItemId,CategoryId,ProducerId,Title,Price,ItemArtUrl")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", item.CategoryId);
            ViewBag.ProducerId = new SelectList(db.Producers, "ProducerId", "Name", item.ProducerId);
            return View(item);
        }
Пример #6
0
        public ActionResult Create([Bind(Include = "Id,Img,Stock,Name,Price,Section")] Products_StoreProduct products_StoreProduct)
        {
            if (ModelState.IsValid)
            {
                if (products_StoreProduct.Img == null)
                {
                    products_StoreProduct.Img = "https://www.allianceplast.com/wp-content/uploads/no-image.png";
                }
                db.Products_StoreProduct.Add(products_StoreProduct);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(products_StoreProduct));
        }
Пример #7
0
        public bool InsertOrder(Order newOrder)
        {
            try
            {
                WebShopEntities db    = new WebShopEntities();
                Order           order = new Order();
                order.email   = newOrder.email;
                order.userId  = newOrder.userId;
                order.address = newOrder.address;
                order.total   = newOrder.total;
                order.status  = newOrder.status;
                order.id      = (from c in db.Orders orderby c.id descending select c.id).First() + 1;
                if (order.id < 10)
                {
                    order.code = "OR00" + order.id;
                }
                else if (order.id >= 10 && order.id < 100)
                {
                    order.code = "OR0" + order.id;
                }
                else
                {
                    order.code = "OR" + order.id;
                }

                db.Orders.Add(order);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #8
0
        public bool InsertCategory(Category newCategory)
        {
            try
            {
                WebShopEntities db       = new WebShopEntities();
                Category        category = new Category();
                category.name        = newCategory.name;
                category.description = newCategory.description;
                category.id          = (from c in db.Categories orderby c.id descending select c.id).First() + 1;
                if (category.id < 10)
                {
                    category.code = "CAT00" + category.id;
                }
                else if (category.id >= 10 && category.id < 100)
                {
                    category.code = "CAT0" + category.id;
                }
                else
                {
                    category.code = "CAT" + category.id;
                }

                db.Categories.Add(category);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        /// <summary>
        /// Método que realiza el guardado de productCategories
        /// en la base de datos.
        /// </summary>
        /// <param name="args">Objeto con los argumentos requeridos.</param>
        /// <returns>String con las respuesta de la operación</returns>
        private string InsertDb(tbl_product_categories args)
        {
            string result = "";

            try
            {
                if (validateExist(args, null))
                {
                    tbl_product_categories category = new tbl_product_categories
                    {
                        description = args.description,
                        last_update = DateTime.Now
                    };
                    db.tbl_product_categories.Add(category);
                    db.SaveChanges();
                    result = "Categoría guardada correctamente";
                }
                else
                {
                    result = "La categoría ya existe en la base de datos";
                }
            }
            catch (Exception error)
            {
                result = error.Message.ToString();
            }
            return(result);
        }
Пример #10
0
        public bool InsertOrderDetail(OrderDetail newOrderDetail)
        {
            try
            {
                WebShopEntities db          = new WebShopEntities();
                OrderDetail     orderDetail = new OrderDetail();

                orderDetail.idProduct  = newOrderDetail.idProduct;
                orderDetail.quantity   = newOrderDetail.quantity;
                orderDetail.price      = newOrderDetail.price;
                orderDetail.totalPrice = newOrderDetail.totalPrice;

                orderDetail.id = (from c in db.OrderDetails orderby c.id descending select c.id).First() + 1;
                if (orderDetail.id < 10)
                {
                    orderDetail.code = "ORDT00" + orderDetail.id;
                }
                else if (orderDetail.id >= 10 && orderDetail.id < 100)
                {
                    orderDetail.code = "ORDT0" + orderDetail.id;
                }
                else
                {
                    orderDetail.code = "ORDT" + orderDetail.id;
                }

                db.OrderDetails.Add(orderDetail);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #11
0
        public bool InsertImportBill(ImportBill newImportBill)
        {
            try
            {
                WebShopEntities db         = new WebShopEntities();
                ImportBill      importBill = new ImportBill();
                importBill.agencyName = newImportBill.agencyName;
                importBill.address    = newImportBill.address;
                importBill.phone      = newImportBill.phone;
                importBill.total      = newImportBill.total;
                importBill.id         = (from c in db.ImportBills orderby c.id descending select c.id).First() + 1;
                if (importBill.id < 10)
                {
                    importBill.code = "IMT00" + importBill.id;
                }
                else if (importBill.id >= 10 && importBill.id < 100)
                {
                    importBill.code = "IMT0" + importBill.id;
                }
                else
                {
                    importBill.code = "IMT" + importBill.id;
                }

                db.ImportBills.Add(importBill);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #12
0
 public bool UpdateProduct(int id, Product newProduct)
 {
     try
     {
         WebShopEntities db      = new WebShopEntities();
         Product         product = db.Products.FirstOrDefault(x => x.id == id);
         if (product == null)
         {
             return(false);
         }
         product.code        = newProduct.code;
         product.name        = newProduct.name;
         product.description = newProduct.description;
         product.detail      = newProduct.detail;
         product.idCategory  = newProduct.idCategory;
         product.price       = newProduct.price;
         product.quantity    = newProduct.quantity;
         product.image       = newProduct.image;
         product.discount    = newProduct.discount;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public string Remove(int id)
        {
            string result = "";

            try
            {
                List <tbl_product_categories> categories = new List <tbl_product_categories>();
                var sessionStorage = Session["isLocalStorage"];
                if (sessionStorage == null || (bool)sessionStorage == false)
                {
                    db.tbl_product_categories.RemoveRange(db.tbl_product_categories.Where(pc => pc.id_product_category == id));
                    db.SaveChanges();
                }
                else
                {
                    categories = (List <tbl_product_categories>)Session["productCategories"];
                    var itemToRemove = categories.Single(r => r.id_product_category == id);
                    categories.Remove(itemToRemove);
                    Session["productCategories"] = categories;
                }
                result = "La Categoría se ha eliminado de forma exitosa.";
            }
            catch (Exception error)
            {
                result = error.Message.ToString();
            }
            return(result);
        }
Пример #14
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Username  = User.Identity.Name;
                    order.OrderDate = DateTime.Now;


                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();

                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return(RedirectToAction("Complete",
                                            new { id = order.OrderId }));
                }
            }
            catch
            {
                return(View(order));
            }
        }
Пример #15
0
        public string Remove(int id)
        {
            string result = "";

            try
            {
                var sessionStorage = Session["isLocalStorage"];
                if (sessionStorage == null || (bool)sessionStorage == false)
                {
                    db.tbl_relationship_pc.RemoveRange(db.tbl_relationship_pc.Where(rel => rel.id_product == id));
                    db.tbl_products.RemoveRange(db.tbl_products.Where(p => p.id_product == id));
                    db.SaveChanges();
                }
                else if ((bool)sessionStorage == true)
                {
                    List <tbl_products> products = (List <tbl_products>)Session["products"];
                    var itemToRemove             = products.Single(p => p.id_product == id);
                    products.Remove(itemToRemove);
                    Session["products"] = products;
                }
                result = "El producto se ha eliminado correctamente.";
            }
            catch (Exception error)
            {
                result = error.Message.ToString();
            }
            return(result);
        }
Пример #16
0
        public bool InsertImportBillDetail(ImportBillDetail newImportBillDetail)
        {
            try
            {
                WebShopEntities  db = new WebShopEntities();
                ImportBillDetail importBillDetail = new ImportBillDetail();
                importBillDetail.quantity   = newImportBillDetail.quantity;
                importBillDetail.price      = newImportBillDetail.price;
                importBillDetail.totalPrice = newImportBillDetail.totalPrice;

                importBillDetail.id = (from c in db.ImportBillDetails orderby c.id descending select c.id).First() + 1;
                if (importBillDetail.id < 10)
                {
                    importBillDetail.code = "IMTDT00" + importBillDetail.id;
                }
                else if (importBillDetail.id >= 10 && importBillDetail.id < 100)
                {
                    importBillDetail.code = "IMTDT0" + importBillDetail.id;
                }
                else
                {
                    importBillDetail.code = "IMTDT" + importBillDetail.id;
                }

                db.ImportBillDetails.Add(importBillDetail);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #17
0
        public ActionResult Create(ShoppingCart shoppingCart)
        {
            foreach (Products_OrderProduct orderProduct in shoppingCart)
            {
                db.Products_StoreProduct.Find(orderProduct.Id).Stock -= orderProduct.Quantity;
            }

            Client myClient = db.Clients.Where(client => client.Name.Equals(User.Identity.Name)).First();
            Order  order    = db.Orders.Add(new Order(shoppingCart, myClient));

            db.SaveChanges();
            shoppingCart.Clear();
            return(RedirectToAction("Details", new { id = order.Id }));
        }
Пример #18
0
 public bool DeleteOrderDetail(int id)
 {
     try
     {
         WebShopEntities db          = new WebShopEntities();
         OrderDetail     orderDetail = db.OrderDetails.FirstOrDefault(x => x.id == id);
         if (orderDetail == null)
         {
             return(false);
         }
         db.OrderDetails.Remove(orderDetail);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #19
0
 public bool DeleteImportBill(int id)
 {
     try
     {
         WebShopEntities db         = new WebShopEntities();
         ImportBill      importBill = db.ImportBills.FirstOrDefault(x => x.id == id);
         if (importBill == null)
         {
             return(false);
         }
         db.ImportBills.Remove(importBill);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #20
0
 public bool DeleteCategory(int id)
 {
     try
     {
         WebShopEntities db       = new WebShopEntities();
         Category        category = db.Categories.FirstOrDefault(x => x.id == id);
         if (category == null)
         {
             return(false);
         }
         db.Categories.Remove(category);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #21
0
 public bool DeleteProduct(int id)
 {
     try
     {
         WebShopEntities db      = new WebShopEntities();
         Product         product = db.Products.FirstOrDefault(x => x.id == id);
         if (product == null)
         {
             return(false);
         }
         db.Products.Remove(product);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #22
0
 public bool UpdateImportBillDetail(int id, ImportBillDetail newImportBillDetail)
 {
     try
     {
         WebShopEntities  db = new WebShopEntities();
         ImportBillDetail importBillDetail = db.ImportBillDetails.FirstOrDefault(x => x.id == id);
         if (importBillDetail == null)
         {
             return(false);
         }
         importBillDetail.quantity   = newImportBillDetail.quantity;
         importBillDetail.price      = newImportBillDetail.price;
         importBillDetail.totalPrice = newImportBillDetail.totalPrice;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #23
0
 public bool UpdateCategory(int id, Category newCategory)
 {
     try
     {
         WebShopEntities db       = new WebShopEntities();
         Category        category = db.Categories.FirstOrDefault(x => x.id == id);
         if (category == null)
         {
             return(false);
         }
         category.code        = newCategory.code;
         category.name        = newCategory.name;
         category.description = newCategory.description;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #24
0
 public bool UpdateOrderDetail(int id, OrderDetail newOrderDetail)
 {
     try
     {
         WebShopEntities db          = new WebShopEntities();
         OrderDetail     orderDetail = db.OrderDetails.FirstOrDefault(x => x.id == id);
         if (orderDetail == null)
         {
             return(false);
         }
         orderDetail.idProduct  = newOrderDetail.idProduct;
         orderDetail.quantity   = newOrderDetail.quantity;
         orderDetail.price      = newOrderDetail.price;
         orderDetail.totalPrice = newOrderDetail.totalPrice;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #25
0
 public bool UpdateOrder(int id, Order newOrder)
 {
     try
     {
         WebShopEntities db    = new WebShopEntities();
         Order           order = db.Orders.FirstOrDefault(x => x.id == id);
         if (order == null)
         {
             return(false);
         }
         order.email   = newOrder.email;
         order.userId  = newOrder.userId;
         order.address = newOrder.address;
         order.total   = newOrder.total;
         order.status  = newOrder.status;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #26
0
 public bool UpdateImportBill(int id, ImportBill newImportBill)
 {
     try
     {
         WebShopEntities db         = new WebShopEntities();
         ImportBill      importBill = db.ImportBills.FirstOrDefault(x => x.id == id);
         if (importBill == null)
         {
             return(false);
         }
         importBill.agencyName = newImportBill.agencyName;
         importBill.code       = newImportBill.code;
         importBill.address    = newImportBill.address;
         importBill.phone      = newImportBill.phone;
         importBill.total      = newImportBill.total;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #27
0
        public bool InsertProduct(Product newProduct)
        {
            try
            {
                WebShopEntities db      = new WebShopEntities();
                Product         product = new Product();
                product.name        = newProduct.name;
                product.description = newProduct.description;
                product.id          = (from c in db.Products orderby c.id descending select c.id).First() + 1;
                if (product.id < 10)
                {
                    product.code = "PRO00" + product.id;
                }
                else if (product.id >= 10 && product.id < 100)
                {
                    product.code = "PRO0" + product.id;
                }
                else
                {
                    product.code = "PRO" + product.id;
                }
                product.detail     = newProduct.detail;
                product.idCategory = newProduct.idCategory;
                product.price      = newProduct.price;
                product.quantity   = newProduct.quantity;
                product.image      = newProduct.image;
                product.discount   = newProduct.discount;

                db.Products.Add(product);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #28
0
 public ActionResult Create(Client client)
 {
     db.Clients.Add(client);
     db.SaveChanges();
     return(RedirectToAction("Index", "Home"));
 }