public ActionResult Login(LoginViewModel model)
        {
            var db = new KhoDb();
            var result = db.LoginAdmin(model.Name, Encryptor.MD5Hash(model.Pwd), true);
            if (!ModelState.IsValid)
            {
                if (result == 1)
                {
                    var user = db.GetByIDAdmin(model.Name);
                    var userSession = new Common.UserLogin();
                    userSession.UserName = user.TenTK;
                    var list = db.GetListCredentialbyAdmin(model.Name);
                    Session.Add(Common.Common.SESSION_CREDENTIAL, list);
                    Session.Add(Common.Common.USER_SESSION, userSession);
                    return RedirectToAction("index", "GiaoDich", new { area = "Admin" });
                }
                else
                {
                    if (result == -1)
                        ModelState.AddModelError("", "Nhập sai password");
                    else
                    {
                        if (result == -2)
                            ModelState.AddModelError("", "Bạn không có quyền đăng nhập");
                    }

                }

            }
            return View();
        }
Beispiel #2
0
 public ActionResult AddCart(string id, float soLuong, float tienTra, float donGia)
 {
     var kho = new KhoDb();
     var product = kho.ViewDetail(id);
     var session = Session[Common.Common.CartSession];
     if (session != null)
     {
         var list = (List<HangHoaList>)session;
         if (list.Exists(x => x.Product.MaHH == id))
         {
             foreach (var item in list)
             {
                 if (item.Product.MaHH == id) item.SoLuong += soLuong;
             }
         }
         else
         {
             var item = new HangHoaList();
             item.Product = product;
             item.SoLuong = soLuong;
             list.Add(item);
         }
         return View(list);
     }
     else
     {
         //add hang vao list
         var item = new HangHoaList();
         item.Product = product;
         item.SoLuong = soLuong;
         var list = new List<HangHoaList>();
         list.Add(item);
         Session[Common.Common.CartSession] = list;
         // add hang vao DB
         // tao Ma Hoa Don
         return View(list);
     }
 }
Beispiel #3
0
        public ActionResult Payment()
        {
            var cart = (List<HangHoaList>)Session[Common.Common.CartSession];
            //tinh tong gia tri cua hoa don
            decimal s = 0;
            foreach (var item in cart)
            {
                s = s + Convert.ToDecimal(item.Product.GiaBan * item.SoLuong);
            }
            // Them HoaDon
            // string NV_ID = Main.Controllers.AccountController.ID_NV;

            HoaDon hd = new HoaDon
            {
                MaHD = new GetMa().MaHoaDon(),
                LoaiHD = false,
                NgayTao = DateTime.Now,
                TenTK_NV = Admin.Controllers.AccountController.id_NV,
                TongTien = Convert.ToDouble(s),
                MaDT=null,
            };
            db.HoaDon.Add(hd);
            db.SaveChanges();
            var detail = new KhoDb();
            foreach (var item in cart)
            {
                var hoadon = new CT_HoaDon();
                hoadon.MaHD = hd.MaHD;
                hoadon.SoLuong = item.SoLuong;
                hoadon.MaHH = item.Product.MaHH;
                hoadon.DonGia = item.Product.GiaBan;
                hoadon.LoiNhuan = Convert.ToDecimal(item.Product.GiaBan - item.Product.GiaNhap);
                detail.Add_CT_HoaDon(hoadon);
            }
            return RedirectToAction("Index", "Cart", new { area = "Sale" });
        }