Example #1
0
        //GET: api/Orders
        public IHttpActionResult GetAll()
        {
            var orderL = new List <OrdersModel>();
            var or     = db.Orders.ToList();

            foreach (var o in or)
            {
                var orderD = new List <Order_detail>();
                var orM    = new OrdersModel();
                orM.ID   = o.ID;
                orM.Date = o.Date;
                orderL.Add(orM);
                var ord = db.Order_details.Where(od => od.OrderID == orM.ID).ToList();
                foreach (var od in ord)
                {
                    var orDM = new Order_detail
                    {
                        ID            = od.ID,
                        Quantity      = od.Quantity,
                        StatusOrder   = od.StatusOrder,
                        TotalPrice    = od.TotalPrice,
                        SubTotalPrice = od.SubTotalPrice,
                        ProductID     = od.ProductID,
                        OrderID       = od.OrderID
                    };
                    orderD.Add(orDM);
                }
                orM.Order_details = orderD.ToList();
            }

            db.SaveChanges();
            return(Ok(orderL));
        }
Example #2
0
        public IHttpActionResult PutOrder_details(int id, Order_details order_details)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order_details.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Save(customer customer)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerViewModel
                {
                    Customer = customer
                };
                return(View("CustomerForm", viewModel));
            }

            if (customer.customer_id == 0)
            {
                db.customers.Add(customer);
            }
            else
            {
                var customerInDb = db.customers.Where(x => x.customer_id == customer.customer_id).SingleOrDefault();
                customerInDb.first_name = customer.first_name;
                customerInDb.last_name  = customer.last_name;
                customerInDb.birth_date = customer.birth_date;
                customerInDb.phone      = customer.phone;
                customerInDb.address    = customer.address;
                customerInDb.city       = customer.city;
                customerInDb.state      = customer.state;
            }

            db.SaveChanges();
            return(RedirectToAction("CustomerList"));
        }
        public ActionResult Create([Bind(Include = "productId,categoryId,brandId,Name,Price,ProductImg")] Product product)
        {
            if (ModelState.IsValid)
            {
                WebImage ProductImg  = null;
                var      newFileName = "";
                var      imagePath   = "";
                //RIJEÅ ITI NESTED IF
                //zašto ne prihvaća HttpPostedFileBase tip??
                if (ProductImg != null)
                {
                    newFileName = Guid.NewGuid().ToString() + "_" +
                                  Path.GetFileName(ProductImg.FileName);
                    imagePath = @"~\Content\Images\" + newFileName;

                    ProductImg.Save(@"~\" + imagePath);
                }
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.brandId    = new SelectList(db.Brands, "BrandId", "Name", product.brandId);
            ViewBag.categoryId = new SelectList(db.Categories, "CategoryId", "Name", product.categoryId);
            return(View(product));
        }
        public IHttpActionResult PutDiscount(int id, Discount discount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != discount.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutProductImage(int id, ProductImage productImage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #7
0
        public object Update(Product product, HttpPostedFileBase up)
        {
            var update = db.Products.SingleOrDefault(p => p.id == product.id);

            if (ModelState.IsValid)
            {
                update.name        = product.name;
                update.price       = product.price;
                update.description = product.description;
                update.category_id = product.category_id;
                if (up != null)
                {
                    String path = Path.Combine(Server.MapPath("~/Uploads"), up.FileName);
                    up.SaveAs(path);
                    update.image = up.FileName;
                }

                db.Entry(update).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details/" + product.id));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Example #8
0
 public ActionResult Create(Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Customers.Add(customer);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Example #9
0
 public ActionResult Create(ProductSold product)
 {
     if (ModelState.IsValid)
     {
         db.ProductSolds.Add(product);
         db.SaveChanges();
     }
     return(View());
 }
Example #10
0
 public ActionResult Create(Store store)
 {
     if (ModelState.IsValid)
     {
         db.Stores.Add(store);
         db.SaveChanges();
     }
     return(View("Index"));
 }
 public ActionResult Update([Bind(Include = "id,name,number_of_product")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View(category));
 }
Example #12
0
        public ActionResult Create([Bind(Include = "Id,Provider_Name")] SalesProvider salesProvider)
        {
            if (ModelState.IsValid)
            {
                db.SalesProviders.Add(salesProvider);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(salesProvider));
        }
        public ActionResult Create([Bind(Include = "GenreId,Name,Description")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genre.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
Example #14
0
        public ActionResult Create([Bind(Include = "Id,Total_Sale")] Sale sale)
        {
            if (ModelState.IsValid)
            {
                db.Sales.Add(sale);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sale));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                db.ProductCategories.Add(productCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productCategory));
        }
Example #16
0
        public ActionResult Create([Bind(Include = "ProveedorId,Nombre,RUC,Celular,Telefono,Correo,Direccion,Estado")] Proveedor proveedor)
        {
            if (ModelState.IsValid)
            {
                db.Proveedor.Add(proveedor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(proveedor));
        }
        public ActionResult Create([Bind(Include = "CategoriaId,Nombre,Descripcion,Estado")] Categoria categoria)
        {
            if (ModelState.IsValid)
            {
                db.Categoria.Add(categoria);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(categoria));
        }
        public ActionResult Create([Bind(Include = "ArtistId,Name")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                db.Artist.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
Example #19
0
        public ActionResult Create([Bind(Include = "Id,Name,Location")] Store store)
        {
            if (ModelState.IsValid)
            {
                db.Stores.Add(store);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(store));
        }
Example #20
0
        public ActionResult Create([Bind(Include = "Id,Name,Price,ProductCategoryId,Discontinued,FeaturedProduct")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductCategoryId = new SelectList(db.ProductCategories, "Id", "Name", product.ProductCategoryId);
            return(View(product));
        }
        public ActionResult Create([Bind(Include = "OrderId,OrderDate,Username,FirstName,LastName,City,Phone,Total,AlbumId")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Order.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AlbumId = new SelectList(db.Album, "AlbumId", "Title", order.AlbumId);
            return(View(order));
        }
Example #22
0
        public ActionResult Create([Bind(Include = "Id,Product_Name,Product_Price,Product_Quantity,Product_Description,Id_Provider")] SalesProduct salesProduct)
        {
            if (ModelState.IsValid)
            {
                db.SalesProducts.Add(salesProduct);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Id_Provider = new SelectList(db.SalesProviders, "Id", "Provider_Name", salesProduct.Id_Provider);
            return(View(salesProduct));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Price,Image,Description,Category_Id")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Category_Id = new SelectList(db.Categories, "Id", "Name", product.Category_Id);
            return(View(product));
        }
Example #24
0
        public ActionResult Create([Bind(Include = "ProductId,StoreId,AmountInStock")] ProductStore productStore)
        {
            if (ModelState.IsValid)
            {
                db.ProductStores.Add(productStore);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", productStore.ProductId);
            ViewBag.StoreId   = new SelectList(db.Stores, "Id", "Name", productStore.StoreId);
            return(View(productStore));
        }
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
            ViewBag.BrandId    = new SelectList(db.Brands, "BrandId", "Name", product.BrandId);
            return(View(product));
        }
        public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistID,Title,Price,AlbumArtUrl")] Album album)
        {
            if (ModelState.IsValid)
            {
                db.Album.Add(album);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistID = new SelectList(db.Artist, "ArtistId", "Name", album.ArtistID);
            ViewBag.GenreId  = new SelectList(db.Genre, "GenreId", "Name", album.GenreId);
            return(View(album));
        }
Example #27
0
        public ActionResult Create([Bind(Include = "ProductoId,CategoriaId,ProveedorId,Denominacion,Descripcion,PrecioUnitario,Existencias,Estado")] Producto producto)
        {
            if (ModelState.IsValid)
            {
                db.Producto.Add(producto);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoriaId = new SelectList(db.Categoria, "CategoriaId", "Nombre", producto.CategoriaId);
            ViewBag.ProveedorId = new SelectList(db.Proveedor, "ProveedorId", "Nombre", producto.ProveedorId);
            return(View(producto));
        }
Example #28
0
        public ActionResult Create([Bind(Include = "OrderDetailId,OrderId,AlbumId,Quantity,UnitPrice")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetail.Add(orderDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AlbumId = new SelectList(db.Album, "AlbumId", "Title", orderDetail.AlbumId);
            ViewBag.OrderId = new SelectList(db.Order, "OrderId", "Username", orderDetail.OrderId);
            return(View(orderDetail));
        }
Example #29
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                if (!values["Accept"].Contains("true"))
                {
                    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));
            }
        }
Example #30
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                order.UserName  = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                //Save Order
                storeDB.Orders.Add(order);
                storeDB.SaveChanges();
                //Process the order
                var cart = ShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(order);

                return(RedirectToAction("Complete",
                                        new { id = order.OrderId }));
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
Example #31
0
 protected void dlUnits_ItemCommand(object source, DataListCommandEventArgs e)
 {
     int id = int.Parse(e.CommandArgument.ToString());
     TaobaoTesting.StoreEntities db = new StoreEntities();
     db.Units.DeleteObject(db.Units.Single(x => x.ID.Equals(id)));
     db.SaveChanges();
     BindUnits();
 }
Example #32
0
 protected void btnAddUnit_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtUnitName.Text.Trim()))
     {
         TaobaoTesting.StoreEntities db = new StoreEntities();
         db.Units.AddObject(new Unit()
         {
             UnitName = txtUnitName.Text.Trim()
         });
         txtUnitName.Text = "";
         db.SaveChanges();
         BindUnits();
     }
 }