예제 #1
0
 public ActionResult AddCategory(Category cate)
 {
     if (ModelState.IsValid)
     {
         db.categories.Add(cate);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult ThemChatLieu(ChatLieu cl)
 {
     if (ModelState.IsValid)
     {
         db.chatLieus.Add(cl);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult ThemThuongHieu(ThuongHieu th)
 {
     if (ModelState.IsValid)
     {
         db.thuongHieus.Add(th);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
        public ActionResult Register(Register r)
        {
            var user = db.account.Where(m => m.UserName == r.UserName).FirstOrDefault();

            if (user == null)
            {
                var cus = db.customer.Where(m => m.Email == r.Email).FirstOrDefault();
                if (cus != null)
                {
                    var account = db.account.Where(m => m.IDCus == cus.IDCus).FirstOrDefault();
                    if (account == null)
                    {
                        Account a = new Account();
                        a.IDCus           = cus.IDCus;
                        a.UserName        = r.UserName;
                        a.PassWord        = r.PassWord;
                        a.ConfirmPassWord = r.ConfirmPassWord;
                        a.Status          = true;
                        db.account.Add(a);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(RedirectToAction("Account", "Account"));
                    }
                }
                else
                {
                    Customer c = new Customer();
                    c.Name    = r.Name;
                    c.Email   = r.Email;
                    c.Phone   = r.Phone;
                    c.Address = r.Address;
                    c.Status  = true;
                    c.Image   = "anh-dai-dien-FB-200.jpg";
                    db.customer.Add(c);
                    db.SaveChanges();
                    Account a = new Account();
                    a.IDCus           = c.IDCus;
                    a.UserName        = r.UserName;
                    a.PassWord        = r.PassWord;
                    a.ConfirmPassWord = r.ConfirmPassWord;
                    a.Status          = true;
                    db.account.Add(a);
                    db.SaveChanges();
                }
                return(RedirectToAction("Account", "Account"));
            }
            else
            {
                ViewBag.errorusername = "";
                return(RedirectToAction("Account", "Account"));
            }
        }
예제 #5
0
        public ActionResult CapNhatDonHang(FormCollection form)
        {
            int id   = (Session["DH"] as Bill).IDBill;
            var bill = db.Bill.Where(m => m.IDBill == id).FirstOrDefault();

            bill.OrderStatus = int.Parse(form["name"].ToString());
            if (int.Parse(form["name"].ToString()) == 4)
            {
                bill.PayMentStatus = 1;
            }
            db.Entry(bill).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            //return RedirectToAction("ChiTietDonHang", "Bill", id);
            return(RedirectToAction("ChiTietDonHang", new RouteValueDictionary(new { controller = "Bill", action = "ChiTietDonHang", Id = id })));
        }
        public ActionResult CapNhatTrangThai(int id)
        {
            var cus = db.customer.Where(m => m.IDCus == id).FirstOrDefault();

            if (cus.Status == false)
            {
                cus.Status = true;
            }
            else
            {
                cus.Status = false;
            }
            db.Entry(cus).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("DanhSachKhachHang"));
        }
예제 #7
0
        public ActionResult AddProduct(Product pro, HttpPostedFileBase Image1, HttpPostedFileBase Image2, HttpPostedFileBase Image3, HttpPostedFileBase Image4, HttpPostedFileBase Image5, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                if (Image1 != null)
                {
                    var filename1 = Path.GetFileName(Image1.FileName);
                    pro.Image1 = filename1;
                    string path1 = Path.Combine(Server.MapPath("~/Content/Images/"), filename1);
                    Image1.SaveAs(path1);
                }
                if (Image2 != null)
                {
                    var filename2 = Path.GetFileName(Image2.FileName);
                    pro.Image2 = filename2;
                    string path2 = Path.Combine(Server.MapPath("~/Content/Images/"), filename2);
                    Image2.SaveAs(path2);
                }
                if (Image3 != null)
                {
                    var filename3 = Path.GetFileName(Image3.FileName);
                    pro.Image3 = filename3;
                    string path3 = Path.Combine(Server.MapPath("~/Content/Images/"), filename3);
                    Image3.SaveAs(path3);
                }
                if (Image4 != null)
                {
                    var filename4 = Path.GetFileName(Image4.FileName);
                    pro.Image4 = filename4;
                    string path4 = Path.Combine(Server.MapPath("~/Content/Images/"), filename4);
                    Image4.SaveAs(path4);
                }
                if (Image5 != null)
                {
                    var filename5 = Path.GetFileName(Image5.FileName);
                    pro.Image5 = filename5;
                    string path5 = Path.Combine(Server.MapPath("~/Content/Images/"), filename5);
                    Image5.SaveAs(path5);
                }
                pro.QuantitySold = 0;
                db.products.Add(pro);
                int quantity = 0;
                for (int i = 1; i <= 10; i++)
                {
                    if (form["size" + i] != null && form["SL" + i] != null)
                    {
                        Size_Product sp = new Size_Product();
                        sp.IDPro    = pro.IDProduct;
                        sp.size     = form["size" + i];
                        sp.Quantity = int.Parse(form["SL" + i]);
                        quantity   += sp.Quantity;
                        db.size_Products.Add(sp);
                    }
                }
                pro.QuantityRemaining = quantity;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <_Category> listcate = new List <_Category>();

            foreach (var item in db.categories.ToList())
            {
                _Category c = new _Category();
                c.IDCategory = item.IDCategory;
                c.Name       = item.Name;
                listcate.Add(c);
            }
            ViewBag.IDCategory = new SelectList(listcate, "IDCategory", "Name", null);
            List <ThuongHieu> listth = new List <ThuongHieu>();

            foreach (var item in db.thuongHieus.ToList())
            {
                ThuongHieu th = new ThuongHieu();
                th.ID   = item.ID;
                th.Name = item.Name;
                listth.Add(th);
            }
            ViewBag.IDThuongHieu = new SelectList(listth, "ID", "Name", null);
            List <ChatLieu> listcl = new List <ChatLieu>();

            foreach (var item in db.chatLieus.ToList())
            {
                ChatLieu cl = new ChatLieu();
                cl.ID  = item.ID;
                cl.Ten = item.Ten;
                listcl.Add(cl);
            }
            ViewBag.IDChatLieu = new SelectList(listcl, "ID", "Ten", null);
            return(View());
        }
예제 #8
0
        public ActionResult ThanhToan(FormCollection form)
        {
            if (form["HinhThuc"] == "1")
            {
                string email = form["email"];
                var    cus   = db.customer.Where(m => m.Email == email).FirstOrDefault();
                if (cus != null && cus.Status == true || cus == null)
                {
                    Register reg = new Register();
                    reg.Name           = form["Name"];
                    reg.Email          = form["Email"];
                    reg.Phone          = form["Phone"];
                    reg.Address        = form["Address"];
                    Session["infocus"] = reg;
                    return(RedirectToAction("PayMent"));
                }
                else
                {
                    ViewBag.errorbanner = "Bạn đã bị cấm mua hàng tại web";
                    return(View());
                }
            }
            try
            {
                Customer c = new Customer();
                int      i = 0;
                foreach (var item in db.customer)
                {
                    if (item.Email == form["Email"])
                    {
                        i = 1;
                        break;
                    }
                }
                if (i != 1)
                {
                    c.Name    = form["Name"];
                    c.Image   = "anh-dai-dien-FB-200.jpg";
                    c.Email   = form["Email"];
                    c.Phone   = form["Phone"];
                    c.Address = form["Address"];
                    c.Status  = true;
                    db.customer.Add(c);
                    db.SaveChanges();
                }
                else
                {
                    string Email = form["Email"];
                    c = db.customer.Where(m => m.Email == Email).FirstOrDefault();
                    if (c.Status == false)
                    {
                        return(View());
                    }
                }
                Bill b = new Bill();
                b.IDCus         = c.IDCus;
                b.DateCreated   = DateTime.Now;
                b.ShippingCost  = 25;
                b.BillTotal     = 0;
                b.PayMentStatus = 0;
                b.OrderStatus   = 1;
                db.Bill.Add(b);
                List <GioHang> lgh         = (List <GioHang>)Session["giohang"];
                double         total       = 0;
                int            quanitysold = 0;
                Product        product     = new Product();
                foreach (var item in lgh)
                {
                    BillDetails bd = new BillDetails();
                    bd.IDBill = b.IDBill;
                    double tongtien = 0;
                    bd.IDProduct = item.ID;
                    bd.Quantity  = item.SoLuong;
                    bd.UnitPrice = item.Gia;
                    bd.Size      = item.Size;
                    tongtien    += (item.Gia * item.SoLuong);
                    db.billDetails.Add(bd);
                    total                     += tongtien;
                    quanitysold               += item.SoLuong;
                    product                    = db.products.Where(m => m.IDProduct == item.ID).FirstOrDefault();
                    product.QuantitySold      += item.SoLuong;
                    product.QuantityRemaining -= item.SoLuong;
                    db.Entry(product).State    = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    var size = db.size_Products.Where(m => m.IDPro == item.ID && m.size == item.Size).FirstOrDefault();
                    size.Quantity       -= item.SoLuong;
                    db.Entry(size).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                total            += 25;
                b.BillTotal       = total;
                db.Entry(b).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                Session["madonhang"] = b.IDBill;
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Template/newoder.html"));
                content = content.Replace("{{NameProduct}}", lgh[0].Ten);
                content = content.Replace("{{Quantity}}", lgh[0].SoLuong.ToString());
                content = content.Replace("{{Price}}", lgh[0].Gia.ToString());


                content = content.Replace("{{HinhAnh}}", lgh[0].HinhAnh);
                content = content.Replace("{{Name}}", c.Name);
                content = content.Replace("{{Email}}", c.Email);
                content = content.Replace("{{Phone}}", c.Phone);
                content = content.Replace("{{Address}}", c.Address);
                content = content.Replace("{{Total}}", total.ToString());

                new MailHelper().SenMail(c.Email, "Đơn hàng mới", content);
                return(RedirectToAction("CheckoutSuccess"));
            }
            catch
            {
                if (form["Name"] == "" || form["Name"] == null)
                {
                    ViewBag.errorName = "Họ tên không được bỏ trống";
                }
                if (form["Email"] == "" || form["Email"] == null)
                {
                    ViewBag.errorEmail = "Email không được bỏ trống";
                }
                if (form["Phone"] == "" || form["Phone"] == null)
                {
                    ViewBag.errorPhone = "SĐT không được bỏ trống";
                }
                if (form["Address"] == "" || form["Address"] == null)
                {
                    ViewBag.errorAddress = "Địa chỉ không được bỏ trống";
                }
                return(View());
            }
        }