public ActionResult EditProfile([Bind(Include = "Customer_ID, Username,Password,Customer_Name,Customer_Phone,Customer_Address,Email")] Customer customer)
 {
     try
     {
         db.Entry(customer).State = EntityState.Modified;
         var result = db.SaveChanges();
         TempData["EditCustomer"] = "Edit profile successful.";
         return(View());
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Error", "Page"));
     }
 }
        public ActionResult Create([Bind(Include = "Supply_Name,Supply_Address")] Supply supply)
        {
            if (ModelState.IsValid)
            {
                db.Supplies.Add(supply);
                var result = db.SaveChanges();
                if (result > 0)
                {
                    TempData["CreateSupply"] = "Create supply successful.";
                }
                return(RedirectToAction("Index"));
            }

            return(View(supply));
        }
Esempio n. 3
0
        public ActionResult Edit([Bind(Include = "Account_ID, Username,Password,FullName,Role,Email,Phone")] Administrator admin)
        {
            if (ModelState.IsValid)
            {
                db.Entry(admin).State = EntityState.Modified;
                var result = db.SaveChanges();
                if (result > 0)
                {
                    TempData["EditManager"] = "Edit profile of manager successful.";
                }
                return(RedirectToAction("Index"));
            }


            return(View(admin));
        }
Esempio n. 4
0
        public ActionResult ProcessOrder()
        {
            List <CartItem> ListCart = (List <CartItem>)Session[strCart];

            // save order
            var       order = new WebApplication.Models.Order();
            UserLogin cus   = (UserLogin)Session[CommonConstants.USER_SESSION];

            order.Order_Date = DateTime.Now;

            order.Customer_ID = cus.Customer_ID;
            order.Status      = "Pending";


            // save od
            foreach (CartItem cart in ListCart)
            {
                OrderDetail orderdetail = new OrderDetail()
                {
                    Quantity         = cart.Quantity,
                    Product_Price    = cart.Product.Product_Price,
                    Product_Discount = cart.Product.Product_Discount,
                    Product_ID       = cart.Product.Product_ID,
                    Order_ID         = order.Order_ID
                };
                var model = db.Products.Single(x => x.Product_ID == cart.Product.Product_ID);

                if (cart.Quantity > model.Quantity)
                {
                    return(RedirectToAction("Fail", "Cart"));
                }
                else
                {
                    db.OrderDetails.Add(orderdetail);
                    db.Orders.Add(order);
                    db.SaveChanges();

                    model.Quantity = model.Quantity - orderdetail.Quantity;
                    db.SaveChanges();
                }
            }


            Session.Remove(strCart);

            return(View("Success"));
        }
        public ActionResult Create([Bind(Include = "Category_Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                if (category.Category_Name == "" || category.Category_Name == null)
                {
                    TempData["FailCreate"] = "Create item fail, please try again !";
                    return(View());
                }
                db.Categories.Add(category);
                var result = db.SaveChanges();
                if (result > 0)
                {
                    TempData["Createcate"] = "Create category successful.";
                }
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Product_Name,Product_Price,Product_Date,Product_Image," +
                                                   "Product_Description,Product_Discount,Category_ID,Supply_ID, Quantity")] Product product, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    if (!isValidContentType(photo.ContentType))
                    {
                        TempData["ErrorImage"] = "The image wrong type, please check again !";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        var fileName = new FileInfo(photo.FileName);;
                        //var path = Path.Combine(Server.MapPath("~/Images"), fileName);
                        photo.SaveAs(Server.MapPath("~/Images/" + fileName));
                        //ViewBag.fileName = photo.FileName;
                        product.Product_Image = photo.FileName;
                    }
                }

                else
                {
                    TempData["ErrorImage"] = "The image wrong type, please check again !";
                    return(RedirectToAction("Index"));
                }

                product.Product_Date = DateTime.Now;
                db.Products.Add(product);
                var result = db.SaveChanges();
                if (result > 0)
                {
                    TempData["CreateProduct"] = "Create Product Successful";
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.Category_ID = new SelectList(db.Categories, "Category_ID", "Category_Name", product.Category_ID);
            ViewBag.Supply_ID   = new SelectList(db.Supplies, "Supply_ID", "Supply_Name", "Supply_Address");
            return(View(product));
        }
Esempio n. 7
0
        public ActionResult Rating([Bind(Include = "RateID,RateStars,Customer_ID,Product_ID")] int rating, Vote vote)
        {
            var session = (WebApplication.Common.UserLogin)Session[WebApplication.Common.CommonConstants.USER_SESSION];

            if (session != null)
            {
                if (ModelState.IsValid)
                {
                    vote.RateStars   = rating;
                    vote.Customer_ID = session.Customer_ID;
                    vote.Product_ID  = (int)TempData["IDDetails"];
                    db.Votes.Add(vote);
                    var result = db.SaveChanges();
                    if (result > 0)
                    {
                        TempData["CreateProduct"] = "Create Product Successful";
                    }
                    return(RedirectToAction("Detail", new { id = (int)TempData["IDDetails"] }));
                }
                return(RedirectToAction("Error", "Page"));
            }
            return(RedirectToAction("Login", "User"));
        }
Esempio n. 8
0
 public long Insert(Customer c)
 {
     db.Customers.Add(c);
     db.SaveChanges();
     return(c.Customer_ID);
 }
        public ActionResult EditStatus([Bind(Include = "Order_Date,Customer_ID,Status,Order_ID")] string submit, Order order)
        {
            if (ModelState.IsValid)
            {
                switch (submit)
                {
                case "Accepted":

                    order.Status          = "Processing";
                    db.Entry(order).State = EntityState.Modified;
                    var data  = db.Orders.Include(x => x.Customer);
                    var check = data.Where(x => x.Order_ID == order.Order_ID).ToList();
                    foreach (var item in check)
                    {
                        if (item.Customer_ID == item.Customer.Customer_ID)
                        {
                            TempData["customerus"]  = item.Customer.Username;
                            TempData["emailcus"]    = item.Customer.Email;
                            TempData["fullnamecus"] = item.Customer.Customer_Name;
                        }
                        else
                        {
                            return(View("CheckOrders"));
                        }
                    }
                    var result = db.SaveChanges();
                    if (result > 0)
                    {
                        TempData["statusaccepted"] = "This order has been accepted";
                    }
                    string content = System.IO.File.ReadAllText(Server.MapPath("~/Theme/client/template/approve.html"));
                    content = content.Replace("{{FullName}}", TempData["fullnamecus"].ToString());
                    content = content.Replace("{{Username}}", TempData["customerus"].ToString());
                    var toEmail = TempData["emailcus"].ToString();
                    if (toEmail != null && toEmail != "")
                    {
                        new MailHelper().SendMail(toEmail, "Jordan Sneaker Receipt", content);
                    }
                    return(RedirectToAction("CheckOrders"));

                    break;

                case "Completed":
                    order.Status          = "Completed";
                    db.Entry(order).State = EntityState.Modified;
                    var data1  = db.Orders.Include(x => x.Customer);
                    var check1 = data1.Where(x => x.Order_ID == order.Order_ID).ToList();
                    foreach (var item in check1)
                    {
                        if (item.Customer_ID == item.Customer.Customer_ID)
                        {
                            TempData["customerus"]  = item.Customer.Username;
                            TempData["emailcus"]    = item.Customer.Email;
                            TempData["fullnamecus"] = item.Customer.Customer_Name;
                        }
                        else
                        {
                            return(View("CheckOrders"));
                        }
                    }
                    var result1 = db.SaveChanges();
                    if (result1 > 0)
                    {
                        TempData["statuscompleted"] = "This order has been completed";
                    }
                    string content1 = System.IO.File.ReadAllText(Server.MapPath("~/Theme/client/template/complete.html"));
                    content = content1.Replace("{{FullName}}", TempData["fullnamecus"].ToString());
                    content = content.Replace("{{Username}}", TempData["customerus"].ToString());
                    var toEmail1 = TempData["emailcus"].ToString();
                    if (toEmail1 != null && toEmail1 != "")
                    {
                        new MailHelper().SendMail(toEmail1, "Jordan Sneaker Receipt", content);
                    }

                    return(RedirectToAction("CheckOrders"));

                    break;

                case "Rejected":
                    order.Status          = "Rejected";
                    db.Entry(order).State = EntityState.Modified;
                    TempData["OrderID"]   = order.Order_ID;

                    return(RedirectToAction("RejectedOrders"));

                    break;

                default:
                    throw new Exception();
                }

                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(order));
        }
Esempio n. 10
0
 public long Insert(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     return(order.Order_ID);
 }