예제 #1
0
 public ActionResult Create([Bind("CategoryName")] Categories C)
 {
     if (ModelState.IsValid)
     {
         context.Categories.Add(C);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(C));
 }
 public ActionResult Create([Bind("ProductName", "ProductPrice", "ProductQuantity", "ProductSize")] Products c)
 {
     if (ModelState.IsValid)
     {
         context.Products.Add(c);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(c));
 }
 public ActionResult Create([Bind("VendorName", "VendorEmail", "VendorPhoneNo")] Vendors V)
 {
     if (ModelState.IsValid)
     {
         context.Vendors.Add(V);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(V));
 }
예제 #4
0
        public ActionResult Create([Bind("BrandName")] Brands B)
        {
            if (ModelState.IsValid)
            {
                context.Brands.Add(B);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(B));
        }
        public ActionResult cusEdit(int id, Customers customers)
        {
            Customers c = context.Customers.Where(x => x.CustomerEmail == customers.CustomerEmail).SingleOrDefault();

            c.CustomerFirstName    = customers.CustomerFirstName;
            c.CustomerLastName     = customers.CustomerLastName;
            c.CustomerPhoneNumber  = customers.CustomerPhoneNumber;
            c.CustomerCountry      = customers.CustomerCountry;
            c.CustomerState        = customers.CustomerState;
            c.CustomerZipNumber    = customers.CustomerZipNumber;
            c.CustomerAddress1     = customers.CustomerAddress1;
            c.CustomerPhoneNumber2 = customers.CustomerPhoneNumber2;
            c.SameAddress          = customers.SameAddress;
            context.SaveChanges();
            SessionHelper.SetObjectAsJson(HttpContext.Session, "cus", c);
            return(RedirectToAction("userprofile", "home", new { @id = customers.CustomerEmail }));
        }
        public IActionResult Buy(int id)
        {
            Customers cus = SessionHelper.GetObectFromJson <Customers>(HttpContext.Session, "cus");
            Carts     c   = new Carts();

            if (SessionHelper.GetObectFromJson <List <Item> >(HttpContext.Session, "cart") == null)
            {
                List <Item> cart = new List <Item>();
                cart.Add(new Item
                {
                    Products = context.Products.Find(id),
                    Quantity = 1
                });
                if (HttpContext.Session.GetString("name") != null)
                {
                    c.ProductId  = id;
                    c.Quantity   = 1;
                    c.CustomerId = cus.CustomerId;
                    SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                    context.Carts.Add(c);
                    context.SaveChanges();
                }
                else
                {
                    SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                }
            }
            else
            {
                List <Item> cart  = SessionHelper.GetObectFromJson <List <Item> >(HttpContext.Session, "cart");
                int         index = isExist(id);
                if (index != -1)
                {
                    cart[index].Quantity++;
                }
                else
                {
                    cart.Add(new Item
                    {
                        Products = context.Products.Find(id),
                        Quantity = 1
                    });
                    if (HttpContext.Session.GetString("name") != null)
                    {
                        c.ProductId  = id;
                        c.Quantity   = 1;
                        c.CustomerId = cus.CustomerId;

                        SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                        context.Carts.Add(c);
                        context.SaveChanges();
                    }
                    else
                    {
                        SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }