Esempio n. 1
0
        public ActionResult Create([Bind(Include = "Id,name,num_of_producta")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult Create([Bind(Include = "Id,name,price,image,description,category_id")] Product product, HttpPostedFileBase imgFile)
        {
            if (ModelState.IsValid)
            {
                string path = "";
                if (imgFile.FileName.Length > 0)
                {
                    path = "~/images/" + Path.GetFileName(imgFile.FileName);
                    imgFile.SaveAs(Server.MapPath(path));
                }
                product.image = path;
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.category_id = new SelectList(db.Categories, "Id", "name", product.category_id);
            return(View(product));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Price,Image,Description,CID")] product product, HttpPostedFileBase imgFile)
        {
            if (ModelState.IsValid)
            {
                string path = "";
                if (imgFile.FileName.Length > 0)
                {
                    path = "~/Images/" + Path.GetFileName(imgFile.FileName);
                    imgFile.SaveAs(Server.MapPath(path));
                }
                product.Image = path;
                db.products.Add(product);
                var categoryindb = db.categories.Single(c => c.CID == product.CID);
                categoryindb.Nun_of_products++;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Id  = new SelectList(db.Carts, "product_id", "product_id", product.Id);
            ViewBag.CID = new SelectList(db.categories, "CID", "CName", product.CID);
            return(View(product));
        }
Esempio n. 4
0
        // GET: Cart
        public ActionResult Addtocart(int id)
        {
            //    var product = db.products.SingleOrDefault(c => c.CID == id);
            //    if (product == null)
            //        return HttpNotFound();

            var cart_list = db.Carts.SingleOrDefault(c => c.product_id == id);

            if (cart_list != null)
            {
                return(RedirectToAction("Index", "products"));
            }
            else
            {
                Cart cart = new Cart();
                cart.product_id = id;
                cart.added_at   = DateTime.Now;
                db.Carts.Add(cart);
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "products"));
        }
Esempio n. 5
0
        public void Insert(CustomerVM customerVM)
        {
            var        entity = new storeDBEntities();
            CustomerVM vm     = new CustomerVM();

            customer customerobj = new customer(); //table

            customerobj.customerid    = customerVM.customerid;
            customerobj.customername  = customerVM.customername;
            customerobj.rewards       = customerVM.rewards;
            customerobj.contactnumber = customerVM.contactnumber;
            customerobj.location      = customerVM.location;

            entity.customers.Add(customerobj);  //db.table-object
            entity.SaveChanges();
        }
Esempio n. 6
0
        public void Insert(ItemsVM Items)
        {
            var     _context = new storeDBEntities();
            ItemsVM vm       = new ItemsVM();

            item newitemobj = new item();             //table

            newitemobj.itemname        = Items.itemname;
            newitemobj.price           = Items.price;
            newitemobj.discount        = Items.discount;
            newitemobj.manufacturedate = Items.manufacturedate;
            newitemobj.expirydate      = Items.expirydate;
            newitemobj.manufacturerid  = 1;
            newitemobj.itemtypeid      = 1;


            _context.items.Add(newitemobj);
            _context.SaveChanges();
        }