Ejemplo n.º 1
0
 public ActionResult Create(FormCollection fc, JF_DonViTinh obj)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dvt = ctx.JF_DonViTinh.Where(x => x.ten == obj.ten && x.kichhoat == true).FirstOrDefault();
             if (dvt != null)
             {
                 ModelState.AddModelError("", "Đã tồn tại đơn vị tính này !");
                 return(View());
             }
             obj.kichhoat = true;
             ctx.JF_DonViTinh.Add(obj);
             ctx.SaveChanges();
             if (obj.id > 0)
             {
                 SetAlert("Thêm mới loại sản phẩm thành công", AlertType.Success);
                 return(RedirectToAction("Index", "JF_DonViTinh"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm mới không thành công");
             }
             return(View("Index"));
         }
         return(View());
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }
Ejemplo n.º 2
0
 public ActionResult Create(FormCollection fc, JF_SanPham obj)
 {
     try
     {
         TempData.Keep("loaisanpham");
         TempData.Keep("donvitinh");
         if (ModelState.IsValid)
         {
             obj.hientrangchu = obj.hientrangchu == null ? false : true;
             obj.noibat       = obj.noibat == null ? false : true;
             obj.kichhoat     = true;
             obj.ngaycapnhat  = DateTime.Now;
             ctx.JF_SanPham.Add(obj);
             ctx.SaveChanges();
             if (obj.id > 0)
             {
                 SetAlert("Thêm mới sản phẩm thành công", AlertType.Success);
                 return(RedirectToAction("Index", "JF_SanPham"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm mới không thành công");
             }
             return(View("Index"));
         }
         return(View());
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }
Ejemplo n.º 3
0
        private void XoaDonHangThua()
        {
            var dhs = ctx.JF_DonHang.Where(x => x.JF_SanPham_DonHang.Count() <= 0);

            if (dhs != null && dhs.Count() > 0)
            {
                foreach (var item in dhs)
                {
                    ctx.JF_DonHang.Remove(item);
                }
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 4
0
 public ActionResult DonDatHang(FormCollection fc, JF_DonHang obj)
 {
     try
     {
         TempData.Keep("htthanhtoan");
         ViewBag.MADONHANG = "DH" + ConvertToUnixTime(DateTime.Now).ToString();
         if (Session["cart"] == null)
         {
             SetAlert("Chưa có sản phẩm nào trong giỏ hàng! ", AlertType.Error);
             return(View());
         }
         if (ModelState.IsValid)
         {
             using (jFoodEntities ctx = new jFoodEntities())
             {
                 List <ShoppingCart> lCart = (List <ShoppingCart>)Session["cart"];
                 obj.kichhoat    = true;
                 obj.trangthai   = 0;
                 obj.ngaydathang = DateTime.Now;
                 ctx.JF_DonHang.Add(obj);
                 ctx.SaveChanges();
                 decimal thanhtien = 0;
                 foreach (var item in lCart)
                 {
                     JF_SanPham_DonHang sp_dh = new JF_SanPham_DonHang();
                     sp_dh.id_donhang = obj.id;
                     sp_dh.id_sanpham = item.idsanpham;
                     sp_dh.soluong    = item.soluong;
                     sp_dh.kichhoat   = true;
                     sp_dh.giatien    = item.giatien;
                     thanhtien        = item.soluong * item.giatien;
                     sp_dh.thanhtien  = thanhtien;
                     ctx.JF_SanPham_DonHang.Add(sp_dh);
                 }
                 ctx.SaveChanges();
                 Session["cart"] = null;
             }
             SetAlert("Đơn hàng " + obj.madonhang + " được tạo thành công!<br/> Vui lòng ghi nhớ mã số đơn hàng. Chúng tôi sẽ liên lạc lại với bạn trong thời gian sớm nhất.", AlertType.Success);
             TempData["donhang"] = obj;
             return(RedirectToAction("success", "GioHang"));
         }
         return(View());
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }
 public ActionResult Index(FormCollection fc, JF_ThongTinLienHe obj)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ctx.Entry(obj).State = EntityState.Modified;
             int cn = ctx.SaveChanges();
             if (cn > 0)
             {
                 SetAlert("Cập nhật thành công", AlertType.Success);
                 return(RedirectToAction("Index", "JF_ThongTinLienHe"));
             }
             else
             {
                 SetAlert("Cập nhật không thành công", AlertType.Error);
             }
         }
         return(View(obj));
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }