Esempio n. 1
0
        public ActionResult Insert(Supplier model)
        {
            try
            {
                //var f = Request.Files["uplLogo"];
                //if (f != null && f.ContentLength > 0)
                //{
                //    model.Logo = model.Id
                //        + f.FileName.Substring(f.FileName.LastIndexOf("."));
                //    f.SaveAs(Server.MapPath("~/images/suppliers/" + model.Logo));

                //}
                var from = Server.MapPath("/photos/" + model.Logo);
                model.Logo = model.Id + model.Logo.Substring(model.Logo.LastIndexOf("."));
                var to = Server.MapPath("/Content/img/suppliers/" + model.Logo);
                System.IO.File.Move(from, to);

                db.Suppliers.Add(model);
                db.SaveChanges();
                ModelState.AddModelError("", "Inserted");
            }
            catch
            {
                ModelState.AddModelError("", "Error");
            }

            ViewBag.Suppliers = db.Suppliers;
            return(View("Index", model));
        }
Esempio n. 2
0
        public ActionResult Insert(Product model)
        {
            try
            {
                var f = Request.Files["uplLogo"];
                if (f != null && f.ContentLength > 0)
                {
                    model.Image = model.Id
                                  + f.FileName.Substring(f.FileName.LastIndexOf("."));
                    f.SaveAs(Server.MapPath("/Content/img/products/" + model.Image));
                }
                db.Products.Add(model);
                db.SaveChanges();
                ModelState.AddModelError("", "Inserted");
            }
            catch
            {
                ModelState.AddModelError("", "Error");
            }

            ViewBag.Products   = db.Products;
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", model.CategoryId);
            ViewBag.SupplierId = new SelectList(db.Suppliers, "Id", "Name", model.SupplierId);
            return(View("Index", model));
        }
Esempio n. 3
0
 public ActionResult Create([Bind(Include = "Id,Password,Fullname,Email,Photo,Activated")] Customer khachhang)
 {
     if (ModelState.IsValid)
     {
         db.Customers.Add(khachhang);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(khachhang));
 }
 public ActionResult Create([Bind(Include = "OrderId,ProductId,UnitPrice,Quantity,Discount")] Supplier chitiet)
 {
     if (ModelState.IsValid)
     {
         db.Suppliers.Add(chitiet);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(chitiet));
 }
 public ActionResult Create([Bind(Include = "CustomerId,OrderDate,RequireDate,Receiver,Address,Description,Amount")] Order dondh)
 {
     if (ModelState.IsValid)
     {
         db.Orders.Add(dondh);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dondh));
 }
Esempio n. 6
0
 public ActionResult Create([Bind(Include = "NameVN,Name,Icon")] Category danmuc)
 {
     if (ModelState.IsValid)
     {
         db.Categories.Add(danmuc);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(danmuc));
 }
 public ActionResult Create([Bind(Include = "Id,Name,Logo,Email,Phone")] Supplier nhasx)
 {
     if (ModelState.IsValid)
     {
         db.Suppliers.Add(nhasx);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nhasx));
 }
Esempio n. 8
0
 public ActionResult Edit([Bind(Include = "Id,OrderId,ProductId,UnitPrice,Quantity,Discount")] OrderDetail orderDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderId   = new SelectList(db.Orders, "Id", "CustomerId", orderDetail.OrderId);
     ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", orderDetail.ProductId);
     return(View(orderDetail));
 }
Esempio n. 9
0
        public ActionResult Purchase(Order model)
        {
            db.Orders.Add(model);

            var cart = ShoppingCart.Cart;

            foreach (var p in cart.Items)
            {
                var d = new OrderDetail
                {
                    Order     = model,
                    ProductId = p.Id,
                    UnitPrice = p.UnitPrice,
                    Discount  = p.Discount,
                    Quantity  = p.Quantity
                };

                db.OrderDetails.Add(d);
            }
            db.SaveChanges();

            // Thanh toán trực tuyến
            //var api = new WebApiClient<AccountInfo>();
            //var data = new AccountInfo {
            //    Id=Request["BankAccount"],
            //    Balance = cart.Total
            //};
            //api.Put("api/Bank/nn", data);
            return(RedirectToAction("Detail", new { id = model.Id }));
        }
Esempio n. 10
0
        public ActionResult Detail(int id, string SupplierID)
        {
            var model = db.Products.Find(id);

            // Tăng số lần xem
            model.Views++;
            db.SaveChanges();

            // Lấy cookie cũ tên views
            var views = Request.Cookies["views"];

            // Nếu chưa có cookie cũ -> tạo mới
            if (views == null)
            {
                views = new HttpCookie("views");
            }
            // Bổ sung mặt hàng đã xem vào cookie
            views.Values[id.ToString()] = id.ToString();
            // Đặt thời hạn tồn tại của cookie
            views.Expires = DateTime.Now.AddMonths(1);
            // Gửi cookie về client để lưu lại
            Response.Cookies.Add(views);

            // Lấy List<int> chứa mã hàng đã xem từ cookie
            var keys = views.Values
                       .AllKeys.Select(k => int.Parse(k)).ToList();

            // Truy vấn háng đãn xem
            ViewBag.Views = db.Products
                            .Where(p => keys.Contains(p.Id));
            return(View(model));
        }
        public ActionResult Purchase(Order model)
        {
            var cart = ShoppingCart.Cart;

            foreach (var p in cart.Items)
            {
                var d = new OrderDetail
                {
                    Order     = model,
                    ProductId = p.Id,
                    UnitPrice = p.UnitPrice,
                    Discount  = p.Discount,
                    Quantity  = p.Quantity,
                };

                db.OrderDetails.Add(d);
            }
            db.SaveChanges(); //Ý ơi cái khúc này bị lỗi có gì p kêu p nhi fix sau tạm thời thanh toán trên paypal

            // Thanh toán trực tuyến
            //var api = new WebApiClient<AccountInfo>();
            //var data = new AccountInfo {
            //    Id=Request["BankAccount"],
            //    Balance = cart.Total
            //};
            //api.Put("api/Bank/nn", data);
            return(RedirectToAction("PaymentWithPayPal", "Payment", model));
        }
Esempio n. 12
0
        public ActionResult Detail(int id, string SupplierID)
        {
            var model = db.Products.Find(id);


            model.Views++;
            db.SaveChanges();


            var views = Request.Cookies["views"];

            if (views == null)
            {
                views = new HttpCookie("views");
            }

            views.Values[id.ToString()] = id.ToString();

            views.Expires = DateTime.Now.AddMonths(1);

            Response.Cookies.Add(views);


            var keys = views.Values
                       .AllKeys.Select(k => int.Parse(k)).ToList();

            ViewBag.Views = db.Products
                            .Where(p => keys.Contains(p.Id));
            return(View(model));
        }
Esempio n. 13
0
        public ActionResult Edit(Product Ma, int CategoryID, string Suppliers)
        {
            //  db.Products.(Id);
            if (ModelState.IsValid)
            {
                Ma.SupplierId = (Suppliers);

                Ma.CategoryId = CategoryID;
                // Ma.UnitBrief ="";
                Ma.ProductDate = DateTime.Now;
                //  Ma.SupplierId = "";
                db.Entry(Ma).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        public ActionResult DangKi(Customer kh)
        {// chen du lieu vao bang
            if (ModelState.IsValid)
            {
                db.Customers.Add(kh); //chen vao bang
                db.SaveChanges();     //luu vao csdl
            }

            return(View());
        }
Esempio n. 15
0
        public ActionResult Detail(int id, string SupplierID)
        {
            string url = "https://vnexpress.net/rss/giai-tri.rss";

            ViewBag.listItems = RSSHelper.read(url);

            var model = db.Products.Find(id);

            // Tăng số lần xem
            model.Views++;
            db.SaveChanges();

            // Lấy cookie cũ tên views
            var views = Request.Cookies["views"];

            // Nếu chưa có cookie cũ -> tạo mới
            if (views == null)
            {
                views = new HttpCookie("views");
            }
            // Bổ sung mặt hàng đã xem vào cookie
            views.Values[id.ToString()] = id.ToString();
            // Đặt thời hạn tồn tại của cookie
            views.Expires = DateTime.Now.AddMonths(1);
            // Gửi cookie về client để lưu lại
            Response.Cookies.Add(views);

            // Lấy List<int> chứa mã hàng đã xem từ cookie
            var keys = views.Values
                       .AllKeys.Select(k => int.Parse(k)).ToList();

            // Truy vấn háng đãn xem
            ViewBag.Views = db.Products
                            .Where(p => keys.Contains(p.Id));
            //Truy vấn sản phẩm bán chạy
            ViewBag.Top = db.Products
                          .Where(p => p.Id > 0).OrderByDescending(p => p.Views).Take(10).ToList();
            return(View(model));
        }