Ejemplo n.º 1
0
        // Cập nhật chi tiết đơn hàng
        public bool UpdateCTDH(CT_PhieuDatHangNCCViewModel model)
        {
            CT_PHIEUDATNCC CTDHExit = context.CT_PHIEUDATNCCs.FirstOrDefault(t => t.TRANGTHAI != 0 && t.MACTPD == model.MaCTPhieuDat);

            if (CTDHExit == null)
            {
                return(false);
            }
            CTDHExit.SOLUONG   = model.SL;
            CTDHExit.GIANHAP   = model.GiaNhap;
            CTDHExit.THANHTIEN = model.SL * CTDHExit.GIANHAP;
            var datHang = context.PHIEUDATHANG_NCCs
                          .Include(t => t.CT_PHIEUDATNCCs)
                          .FirstOrDefault(t => t.MAPHIEUDAT == CTDHExit.MAPHIEUDAT && t.TRANGTHAI == 1);

            if (datHang == null)
            {
                return(false);
            }

            //tinh tong tien

            var newTongTien = datHang.CT_PHIEUDATNCCs.Where(t => t.TRANGTHAI != 0).
                              Sum(t => t.SOLUONG * t.GIANHAP);

            //update tong tien

            datHang.TONGTIEN = newTongTien;

            //save
            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 2
0
        //Xóa chi tiết đơn đặt hàng
        public bool DeleteDetail(int maCTDH)
        {
            CT_PHIEUDATNCC CTDHExit = context.CT_PHIEUDATNCCs.FirstOrDefault(t => t.TRANGTHAI != 0 && t.MACTPD == maCTDH);

            if (CTDHExit == null)
            {
                return(false);
            }
            CTDHExit.TRANGTHAI = 0;
            // update tong tien
            //lay dat hang

            var datHang = context.PHIEUDATHANG_NCCs
                          .Include(t => t.CT_PHIEUDATNCCs)
                          .FirstOrDefault(t => t.MAPHIEUDAT == CTDHExit.MAPHIEUDAT && t.TRANGTHAI != 0);

            if (datHang == null)
            {
                return(false);
            }

            ////////tinh tong tien

            var newTongTien = datHang.CT_PHIEUDATNCCs.Where(t => t.TRANGTHAI == 1).
                              Sum(t => t.SOLUONG * t.GIANHAP);

            //update tong tien

            datHang.TONGTIEN = newTongTien;

            //save
            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 3
0
        public bool AddPhieuDatHangNCC(PhieuDatHang_NCCViewModel model)
        {
            var tongTien = model.ChiTietPhieuDats.Sum(t => t.SL * t.GiaNhap);
            var phieuDat = new PHIEUDATHANG_NCC()
            {
                MANCC     = model.MaNCC,
                NGAYDAT   = DateTime.Now,
                NGUOIDAT  = HttpContext.Current.User.Identity.Name,
                TONGTIEN  = tongTien,
                TRANGTHAI = 1,
            };

            context.PHIEUDATHANG_NCCs.Add(phieuDat);
            context.SaveChanges();

            foreach (var detail in model.ChiTietPhieuDats)
            {
                var chiTiet = new CT_PHIEUDATNCC()
                {
                    MAPHIEUDAT = phieuDat.MAPHIEUDAT,
                    MASANPHAM  = detail.MaSP,
                    SOLUONG    = detail.SL,
                    GIANHAP    = detail.GiaNhap,
                    THANHTIEN  = detail.SL * detail.GiaNhap,
                    TRANGTHAI  = 1,
                };
                context.CT_PHIEUDATNCCs.Add(chiTiet);
            }
            context.SaveChanges();
            return(true);
        }
        public bool Update(CT_PhieuDatHangNCCViewModel model)
        {
            CT_PHIEUDATNCC pdh = context.CT_PHIEUDATNCCs.FirstOrDefault(t => t.MAPHIEUDAT == model.MaPhieuDat);

            if (pdh == null)
            {
                return(false);
            }
            pdh.MASANPHAM = model.MaSP;
            pdh.SOLUONG   = model.SL;
            pdh.GIANHAP   = model.GiaNhap;
            pdh.THANHTIEN = model.ThanhTien;

            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 5
0
        public bool AddCTPhieuDatHangNCC(int id, PhieuDatHang_NCCViewModel model)
        {
            var tongTien = model.ChiTietPhieuDats.Sum(t => t.SL * t.GiaNhap);

            foreach (var detail in model.ChiTietPhieuDats)
            {
                var chiTiet = new CT_PHIEUDATNCC()
                {
                    MAPHIEUDAT = id,
                    MASANPHAM  = detail.MaSP,
                    SOLUONG    = detail.SL,
                    GIANHAP    = detail.GiaNhap,
                    THANHTIEN  = detail.SL * detail.GiaNhap,
                    TRANGTHAI  = 1,
                };
                context.CT_PHIEUDATNCCs.Add(chiTiet);
            }
            context.SaveChanges();
            return(true);
        }
 public bool Add(CT_PhieuDatHangNCCViewModel model)
 {
     try
     {
         var dathang = new CT_PHIEUDATNCC
         {
             MAPHIEUDAT = model.MaPhieuDat,
             MASANPHAM  = model.MaSP,
             SOLUONG    = model.SL,
             GIANHAP    = model.GiaNhap,
             THANHTIEN  = model.ThanhTien,
         };
         context.CT_PHIEUDATNCCs.Add(dathang);
         context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }