Пример #1
0
        public IHttpActionResult PostThueDia(int maKhachHang, int maDia)
        {
            string err    = null;
            var    dia    = db.Dias.Find(maDia);
            var    tieuDe = db.TieuDes.Find(dia.MaTieuDe);
            var    soNgayChoThueMoiDia = db.DanhMucs.Find(tieuDe.MaDanhMuc).ThoiGianThue;
            var    kh = db.KhachHangs.Where(x => x.MaKhachHang == maKhachHang).FirstOrDefault();

            if (dia == null || kh == null)
            {
                err = "Lỗi";
                return(Json(err));
            }
            var model = new DsChoThue
            {
                MaKhachHang = maKhachHang,
                MaDia       = maDia,
                NgayThue    = DateTime.Now,
                NgayPhaiTra = DateTime.Now.AddDays(soNgayChoThueMoiDia),
                NgayThucTra = new DateTime(1753, 1, 1),
                Dia         = dia,
                KhachHang   = kh
            };

            db.DsChoThue.Add(model);
            dia.TinhTrangThue   = Models.Enums.TinhTrangThueCollection.DangThue;
            db.Entry(dia).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(Json(model));
        }
Пример #2
0
        public IHttpActionResult Put(int maKh, int maTieuDe, int thuTu)
        {
            string err   = null;
            var    model = db.DsDatHang.Where(x => x.MaKhachHang == maKh && x.MaTieuDe == maTieuDe && x.ThuTu == thuTu).FirstOrDefault();

            try
            {
                db.DsDatHang.Remove(model);
                db.SaveChanges();
            }
            catch (Exception)
            {
                err = "Lỗi";
                return(Json(err));
            }
            if (KiemTraTieuDeDangDuocDatHang(maTieuDe))
            {
                var model2 = db.DsDatHang.Where(x => x.MaTieuDe == maTieuDe && x.TinhTrang == TinhTrangDatHangCollection.DangCho).
                             OrderBy(x => x.ThuTu).FirstOrDefault();
                model2.TinhTrang       = TinhTrangDatHangCollection.DaXong;
                db.Entry(model2).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                var dia = db.Dias.Where(x => x.MaTieuDe == maTieuDe && x.TinhTrangThue == TinhTrangThueCollection.DangGiu).FirstOrDefault();
                dia.TinhTrangThue   = TinhTrangThueCollection.CoSan;
                db.Entry(dia).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(Json(err));
        }
Пример #3
0
        public async Task <IHttpActionResult> PutKhachHang(int id, KhachHang khachHang)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != khachHang.MaKhachHang)
            {
                return(BadRequest());
            }

            db.Entry(khachHang).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KhachHangExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public IHttpActionResult PostThanhToan(DsChoThue entity)
        {
            string err = null;

            if (entity == null)
            {
                err = "Không tìm thấy dữ liệu";
                return(Json(err));
            }
            var model = db.DsChoThue.Where(x => x.MaKhachHang == entity.MaKhachHang && x.MaDia == x.MaDia &&
                                           x.NgayThue.CompareTo(entity.NgayThue) == 0).FirstOrDefault();

            model.DaThanhToanPhiTre = true;
            db.Entry(model).State   = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(Ok());
        }
Пример #5
0
 public IHttpActionResult Put(KhachHang kh)
 {
     db.Entry(kh).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(Ok());
 }