public async Task <IHttpActionResult> Delete(string id) { var result = new TransferObj <bool>(); DATPHONG instance = await _service.Repository.FindAsync(id); if (instance == null) { return(NotFound()); } try { _service.Delete(instance.ID); int del = await _service.UnitOfWork.SaveAsync(); if (del > 0) { result.Data = true; result.Status = true; result.Message = "Hủy đặt thành công"; } else { result.Data = false; result.Status = false; result.Message = "Thao tác không thành công"; } } catch (Exception e) { result.Data = false; result.Status = false; result.Message = e.Message; } return(Ok(result)); }
public List <IQueryFilter> GetFilters() { var result = new List <IQueryFilter>(); var refObj = new DATPHONG(); if (!string.IsNullOrEmpty(this.MAPHONG)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.MAPHONG), Value = this.MAPHONG, Method = FilterMethod.Like }); } return(result); }
public async Task <IHttpActionResult> Put(string id, DATPHONG instance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != instance.ID) { return(BadRequest()); } var result = new TransferObj <DATPHONG>(); if (id != instance.ID) { result.Status = false; result.Message = "Mã ID không hợp lệ"; return(Ok(result)); } try { var item = _service.Update(instance); int upd = await _service.UnitOfWork.SaveAsync(); if (upd > 0) { result.Status = true; result.Data = item; result.Message = "Cập nhật giờ đặt thành công"; } else { result.Status = false; result.Data = null; result.Message = "Thao tác không thành công"; } } catch (Exception e) { result.Data = null; result.Status = false; result.Message = e.Message; } return(Ok(result)); }
public ActionResult ThanhToan(string txtName, string txtCMND, string txtPhone, string txtEmail) { var cart = Session[CommonConstants.DatPhongSession]; var list = new List <DatPhongItem>(); if (cart != null && txtName != "" && txtPhone.Length > 9) { list = (List <DatPhongItem>)cart; //thêm thông tin giao hàng var datPhong = new DATPHONG(); db.DATPHONGs.Add(datPhong); db.SaveChanges(); //them chi tiết bill foreach (var item in list) { //var phong = db.PHONGs.Where(p => p.LOAIPHONG_ID == item.loaiphongId && p.LOAITINHTRANG_ID == 1).FirstOrDefault(); // phong trong //var chiTietDatPhong = new CHITIETDATPHONG(); //chiTietDatPhong.DATPHONG_ID = datPhong.ID; //chiTietDatPhong.PHONG_ID = phong.ID; //chiTietDatPhong. = txtName; //chiTietDatPhong.sodienthoai = txtPhone; //chiTietDatPhong.socmt = txtCMND; //chiTietDatPhong.email = txtEmail; //chiTietDatPhong.ngaydukienden = Convert.ToDateTime(item.ngaydukienden); //chiTietDatPhong.ngaydukiendi = Convert.ToDateTime(item.ngaydukiendi); //phong.LOAITINHTRANG_ID = 3; //db.SaveChanges(); //db.CHITIETDATPHONGs.Add(chiTietDatPhong); //db.SaveChanges(); } ViewBag.suc = "Đặt phòng thành công ! Chúng tôi sẽ liên hệ với quý khách sớm nhất ."; Session[CommonConstants.DatPhongSession] = null; return(View()); } else { ViewBag.err = "Giỏ hàng chủa có sản phầm nào , hoặc bạn nhập thiếu thông tin khách hàng !"; return(View(list)); } }
public ActionResult DatPhong(FormCollection collection, KHACHHANG kh, THUEPHONG th, DATPHONG dp, PHONG p) { ViewBag.MaPhong = new SelectList(db.PHONGs.ToList().OrderBy(n => n.TenPhong), "MaPhong", "TenPhong"); string spdt = ""; string sptp = ""; Random rnd = new Random(); var makh = rnd.Next(1, 10000000); var tenkh = collection["TenKH"]; var sdt = collection["SDT"]; var cmnd = collection["CMND"]; var passport = collection["PassPort"]; var ngaydat = string.Format("{0:dd/MM/yyyy}", collection["NgayDat"]); var maphong = collection["MaPhong"]; var ngayden = string.Format("{0:dd/MM/yyyy}", collection["NgayDen"]); var ngaydi = string.Format("{0:dd/MM/yyyy}", collection["NgayDi"]); kh.MaKH = makh.ToString(); kh.HoTen = tenkh; int sdt1 = int.Parse(sdt); kh.SDT = sdt1; int cmnd1 = int.Parse(cmnd); kh.CMND = cmnd1; kh.Passport = passport; kh.PhanLoaiKH = "ThuePhong"; dp.SoPhieuDP = RandomSPDT(spdt); dp.MaKH = makh.ToString(); dp.NgayDat = DateTime.Parse(ngaydat).ToShortDateString(); dp.TienDat = 5000000; th.SoPhieuTP = RandomSPTP(sptp); th.SoPhieuDP = dp.SoPhieuDP; th.MaKH = makh.ToString(); th.MaPhong = maphong; th.Ngayden = DateTime.Parse(ngayden).ToShortDateString(); th.Ngaydi = DateTime.Parse(ngaydi).ToShortDateString(); if (maphong == p.MaPhong) { p.Tinhtrang = "Đã Thuê"; } db.KHACHHANGs.InsertOnSubmit(kh); db.DATPHONGs.InsertOnSubmit(dp); db.THUEPHONGs.InsertOnSubmit(th); UpdateModel(p); db.SubmitChanges(); ViewBag.ThongBao = "Đã đặt phòng thành công"; return(View()); }
public int addDP(DATPHONG dp) { mydb.DATPHONGs.Add(dp); mydb.SaveChanges(); return(dp.MaPhieuDat); }
public int addDP(DATPHONG dp) { connectQLKS.DATPHONGs.Add(dp); connectQLKS.SaveChanges(); return(dp.MaPhieuDat); }
public ActionResult DetailRoom(int?maKS, int?maLoaiPhong, DatPhong dp, string ngayBatDau, string ngayKetThuc) { //Check Login var user = Session["loginSuccess"] as UserName; ViewBag.User = null; if (user != null) { ViewBag.User = user.maKH; } //Tìm Hotel var dbhotel = db.KHACHSANs.SingleOrDefault(m => m.MaKS == maKS); //List rooms of this Hotel var dblistloaiPhong = db.LOAIPHONGs.Where(m => m.MaKS == maKS).ToList(); Hotel hotel = new Hotel(dbhotel.MaKS, dbhotel.TenKS, dbhotel.SoSao, dbhotel.SoNha, dbhotel.Quan, dbhotel.ThanhPho, dbhotel.GiaTB, dbhotel.MoTa); ViewBag.Hotel = hotel; ViewBag.maLoaiPhong = maLoaiPhong.ToString(); List <LoaiPhong> listLoaiPhong = new List <LoaiPhong>(); foreach (var item in dblistloaiPhong) { listLoaiPhong.Add(new LoaiPhong(item.MaLoaiPhong, item.TenLoaiPhong, item.MaKS)); } ViewBag.listLoaiPhong = listLoaiPhong; //Get this day DateTime thisDay = DateTime.Today; DateTime ngayDat = DateTime.Today; if (ngayBatDau != null && ngayBatDau != "") { String[] sub = ngayBatDau.Split('-'); ngayDat = new DateTime(int.Parse(sub[0]), int.Parse(sub[1]), int.Parse(sub[2])); } string this_day = thisDay.ToString("yyyy-MM-dd"); ViewBag.thisday = this_day; ViewBag.ngayDatPhong = ngayBatDau; ViewBag.ngayDatPhong = ngayKetThuc; if (maLoaiPhong != null) { //GEt listPhong var dblstPhong = db.DanhSachPhong(maLoaiPhong).ToList().OrderBy(m => m.SoPhong); var dbStage = db.TrangThaiPhongDaDatTheoNgay(maLoaiPhong, ngayDat).OrderBy(m => m).ToList(); var phongtrongs = dblstPhong.Select(x => new Phong { maPhong = x.MaPhong, soPhong = x.SoPhong, stage = dbStage.Any(p => p == x.MaPhong) ? "hết phòng" : "còn phòng" }).ToList(); List <Phong> listPhong = new List <Phong>(); //Lay tình trạng phòng ViewBag.listPhong = phongtrongs; //Book Room ViewBag.ThongBao = ""; int i = 0; if (dp.maPhong != null) { //dp.ngayBatDau = DateTime.ParseExact(ngayBatDau,"MM/dd/yyyy", CultureInfo.InvariantCulture); //dp.ngayTraPhong = DateTime.ParseExact(ngayKetThuc, "MM/dd/yyyy", CultureInfo.InvariantCulture); dp.ngayBatDau = DateTime.Parse(ngayBatDau); dp.ngayTraPhong = DateTime.Parse(ngayKetThuc); if (DateTime.Compare(dp.ngayBatDau, dp.ngayTraPhong) <= 0) { dp.maKH = user.maKH; dp.ngayDat = thisDay; int numDaysDiff = Math.Abs(dp.ngayBatDau.Subtract(dp.ngayTraPhong).Days) + 1; dp.donGia = numDaysDiff * dp.donGia; dp.tinhTrang = "chưa xác nhận"; var test = false; DateTime start = dp.ngayBatDau; for (i = 0; i < numDaysDiff; i++) { test = TrangThaiPhongTheoNgay(dp.maPhong, start.AddDays(i)); if (test) { ViewBag.ThongBao = "Dat Phong That Bai"; break; } } if (!test) { ViewBag.ThongBao = "Dat Phong Thanh Cong"; DATPHONG datphong = new DATPHONG(); datphong.MaPhong = dp.maPhong; datphong.MaKH = dp.maKH; datphong.NgayBatDau = dp.ngayBatDau; datphong.NgayTraPhong = dp.ngayTraPhong; datphong.NgayDat = thisDay; datphong.DonGia = dp.donGia; datphong.MoTa = "ABC"; datphong.TinhTrang = "chưa xác nhận"; //Cap nhat bang dat Phong db.DATPHONGs.Add(datphong); //Cap nhat bang Trang Thai Phong TRANGTHAIPHONG ttp1 = null; for (i = 0; i < numDaysDiff; i++) { //TrangThaiPhongTheoNgay(dp.maPhong, dp.ngayBatDau.AddDays(i)); ttp1 = new TRANGTHAIPHONG(); ttp1.MaPhong = (int)dp.maPhong; ttp1.Ngay = dp.ngayBatDau.AddDays(i); ttp1.TinhTrang = "đang sử dụng"; db.TRANGTHAIPHONGs.Add(ttp1); } db.SaveChanges(); var dathuephong = phongtrongs.FirstOrDefault(x => x.maPhong == datphong.MaPhong); var dathuephongThuTu = Array.IndexOf(phongtrongs.ToArray(), dathuephong); phongtrongs.ElementAt(dathuephongThuTu).stage = "hết phòng"; ViewBag.listPhong = phongtrongs; } } } } return(View()); }