public string AddTraveller(TravellerModel travellerModel)
        {
            string result = string.Empty;

            using (HotelDBContext travellerEntities = new HotelDBContext())
            {
                try
                {
                    Traveller traveller = new Traveller();
                    traveller.FirstName    = travellerModel.FirstName;
                    traveller.MiddleName   = travellerModel.MiddleName;
                    traveller.LastName     = travellerModel.LastName;
                    traveller.MobileNo     = travellerModel.MobileNo;
                    traveller.EmailId      = travellerModel.EmailId;
                    traveller.Gender       = travellerModel.Gender;
                    traveller.Address      = travellerModel.Address;
                    traveller.FirstName_2  = travellerModel.FirstName_2;
                    traveller.MiddleName_2 = travellerModel.MiddleName_2;
                    traveller.LastName_2   = travellerModel.LastName_2;
                    traveller.CreatedOn    = System.DateTime.Now.ToShortDateString();
                    travellerEntities.Entry(traveller).State = System.Data.Entity.EntityState.Added;
                    travellerEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception ex)
                {
                    Log.Error("Failed To Insert", ex);
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Example #2
0
        public string AddPayment(PaymentModel model)
        {
            string result = string.Empty;

            using (HotelDBContext dBEntities = new HotelDBContext())
            {
                try
                {
                    Payment paymentTbl = new Payment();
                    paymentTbl.BookingId  = model.BookingId;
                    paymentTbl.CardNumber = model.CardNumber;
                    paymentTbl.NameOnCard = model.NameOnCard;
                    paymentTbl.ExpiryDate = model.ExpiryDate;
                    paymentTbl.Status     = model.Status;
                    paymentTbl.CreatedOn  = System.DateTime.Now.ToShortDateString();
                    dBEntities.Entry(paymentTbl).State = System.Data.Entity.EntityState.Added;
                    dBEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception)
                {
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Example #3
0
        public string UpdateRoom(RoomTypeModel roomType)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    RoomType roomTbl = new RoomType();
                    roomTbl.Id         = roomType.Id;
                    roomTbl.RoomName   = roomType.RoomName;
                    roomTbl.Amenities  = roomType.Amenities;
                    roomTbl.ImagePath  = roomType.ImagePath;
                    roomTbl.ModifiedOn = System.DateTime.Now.ToShortDateString();
                    _hotelEntities.RoomTypes.Add(roomTbl);
                    _hotelEntities.Entry(roomTbl).State = System.Data.Entity.EntityState.Modified;
                    _hotelEntities.SaveChanges();
                    result = "Record Updated";
                }
                catch (Exception)
                {
                    result = "Failed To Upadate";
                }
                return(result);
            }
        }
Example #4
0
 public IEnumerable <BookingViewModel> GetAllBookings()
 {
     using (HotelDBContext _hotelEntities = new HotelDBContext())
     {
         var data = _hotelEntities.Bookings.ToList();
         List <BookingViewModel> bookingList = new List <BookingViewModel>();
         for (var i = 0; i < data.Count; i++)
         {
             BookingViewModel bookingView = new BookingViewModel();
             bookingView.Id            = data[i].Id;
             bookingView.InvoiceNumber = data[i].InvoiceNumber;
             bookingView.HotelId       = Convert.ToInt32(data[i].HotelId);
             bookingView.RoomId        = Convert.ToInt32(data[i].RoomId);
             RoomTypeModel roomModel = GetAllRoomType().SingleOrDefault(x => x.Id == bookingView.RoomId);
             bookingView.FromDate    = roomModel.RoomName;
             bookingView.ToDate      = roomModel.RoomName;
             bookingView.BookingDate = roomModel.RoomName;
             bookingView.Adult       = data[i].Adult;
             bookingView.Children    = data[i].Children;
             bookingView.BuyingPrice = data[i].BuyingPrice;
             bookingList.Add(bookingView);
         }
         return(bookingList);
     }
 }
Example #5
0
 public HotelModel GetHotelById(int hotelID)
 {
     using (HotelDBContext _hotelEntities = new HotelDBContext())
     {
         var data = _hotelEntities.Hotels.ToList();
         List <HotelModel> hotelList = new List <HotelModel>();
         for (var i = 0; i < data.Count; i++)
         {
             HotelModel model = new HotelModel();
             model.Id                 = data[i].Id;
             model.HotelName          = data[i].HotelName;
             model.Address            = data[i].Address;
             model.CityId             = data[i].CityId;
             model.CountryId          = data[i].CountryId;
             model.PhoneNumber        = data[i].PhoneNumber;
             model.CancellationPolicy = data[i].CancellationPolicy;
             model.Description        = data[i].Description;
             model.DefaultCurrency    = data[i].DefaultCurrency;
             model.PricePerNight      = data[i].PricePerNight;
             hotelList.Add(model);
         }
         HotelModel getHotelData = hotelList.SingleOrDefault(x => x.Id == hotelID);
         return(getHotelData);
     }
 }
        // GET: BookNow
        public ActionResult Information(List <RoomSelected> model)
        {
            HotelDBContext      db         = new HotelDBContext();
            TypeRoomModel       tpm        = new TypeRoomModel();
            OrderModel          om         = new OrderModel();
            double              TotalPrice = 0;
            List <RoomSelected> list       = new List <RoomSelected>();

            for (int i = 0; i < model.Count; i++)
            {
                if (model.ElementAt(i).Checked)
                {
                    model.ElementAt(i).Price = tpm.FindPrice(model.ElementAt(i).RoomID);
                    double TotalDate = (model.ElementAt(i).ToDate - model.ElementAt(i).FromDate).TotalDays;
                    model.ElementAt(i).TotalPrice = TotalDate * model.ElementAt(i).Price;
                    TotalPrice += model.ElementAt(i).TotalPrice;
                    list.Add(model.ElementAt(i));
                }
            }
            SearchInput search = (SearchInput)Session["Search"];

            if (list.Count != search.NumberOfRoom)
            {
                ModelState.AddModelError("NumberOfRoom", $"Please choose {search.NumberOfRoom} room(s)");
                ViewBag.TypeRoom = db.TypeRooms.Find(search.TypeRoomID);
                return(View("~/Views/Home/Search.cshtml", model));
            }
            Bill bill = new Bill();

            bill.Total           = TotalPrice;
            bill.Rooms           = list;
            Session["FinalBill"] = bill;
            return(View(bill));
        }
Example #7
0
 public void TestMethod1()
 {
     //__MigrationHistory这个表为ef中Code first的编程方式
     //如果通过code first自动生成的数据库,就会存在这个表,这个表存在代码自动生成数据库
     //后续程序启动程序就会判断该表是否存在,如果存在就代码使用的是code first代码创建的数据库
     //如果不存在代表使用的是code first数据库优先的方式
     //两种模式不可混用
     //以下代码在数据库不存在的情况下,可自动创建数据库表
     //一旦数据实体更改增加字段,那么就需要采用ef数据迁移的方式更新数据库
     //就算手动更新了数据库,增加了字段,保证了与实体的一致也达不到效果,也将报错
     //可以删除__MigrationHistory表,代表采用的是code first中的数据库优先,这时保证数据库接口与实体的结构一直就可以保存成功
     try
     {
         UserInfo u = new UserInfo()
         {
             Id        = "2",
             UserCode  = "1",
             UserName  = "******",
             PassWord  = "******",
             PassWord3 = "2",
             PassWord4 = "2"
         };
         using (HotelDBContext contenxt = new HotelDBContext())
         {
             contenxt.customer.Add(u);
             contenxt.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Example #8
0
 public IEnumerable <HotelViewModel> GetAllHotels()
 {
     using (HotelDBContext _hotelEntities = new HotelDBContext())
     {
         var data = _hotelEntities.Hotels.ToList();
         List <HotelViewModel> hotelList = new List <HotelViewModel>();
         for (var i = 0; i < data.Count; i++)
         {
             HotelViewModel hotelView = new HotelViewModel();
             hotelView.Id                 = data[i].Id;
             hotelView.HotelName          = data[i].HotelName;
             hotelView.Address            = data[i].Address;
             hotelView.PhoneNumber        = data[i].PhoneNumber;
             hotelView.CancellationPolicy = data[i].CancellationPolicy;
             hotelView.Description        = data[i].Description;
             hotelView.CountryId          = Convert.ToInt32(data[i].CountryId);
             CountryModel countryModel = GetAllCountry().SingleOrDefault(x => x.Id == hotelView.CountryId);
             hotelView.CountryName = countryModel.CountryName;
             hotelView.CityId      = Convert.ToInt32(data[i].CityId);
             CityModel cityModel = GetAllCity().SingleOrDefault(x => x.Id == hotelView.CityId);
             hotelView.CityName        = cityModel.CityName;
             hotelView.PricePerNight   = Convert.ToDecimal(data[i].PricePerNight);
             hotelView.DefaultCurrency = data[i].DefaultCurrency;
             hotelList.Add(hotelView);
         }
         return(hotelList);
     }
 }
Example #9
0
        public string AddBooking(BookingModel model)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    Booking bookingTbl = new Booking();
                    bookingTbl.InvoiceNumber  = model.InvoiceNumber;
                    bookingTbl.HotelId        = model.HotelId;
                    bookingTbl.RoomId         = model.RoomId;
                    bookingTbl.FromDate       = model.FromDate;
                    bookingTbl.ToDate         = model.ToDate;
                    bookingTbl.BookingDate    = model.BookingDate;
                    bookingTbl.BuyingPrice    = model.BuyingPrice;
                    bookingTbl.BuyingCurrency = model.BuyingCurrency;
                    bookingTbl.CreatedOn      = System.DateTime.Now.ToShortDateString();
                    _hotelEntities.Entry(bookingTbl).State = System.Data.Entity.EntityState.Added;
                    _hotelEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception)
                {
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Example #10
0
        public string AddHotel(HotelModel model)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    Hotel hotel = new Hotel();
                    hotel.HotelName                   = model.HotelName;
                    hotel.Address                     = model.Address;
                    hotel.CityId                      = model.CityId;
                    hotel.CountryId                   = model.CountryId;
                    hotel.PhoneNumber                 = model.PhoneNumber;
                    hotel.Description                 = model.Description;
                    hotel.CancellationPolicy          = model.CancellationPolicy;
                    hotel.DefaultCurrency             = model.DefaultCurrency;
                    hotel.PricePerNight               = model.PricePerNight;
                    hotel.CreatedOn                   = System.DateTime.Now.ToShortDateString();
                    _hotelEntities.Entry(hotel).State = System.Data.Entity.EntityState.Added;
                    _hotelEntities.SaveChanges();
                    result = "Record Inserted";
                }
                catch (Exception)
                {
                    result = "Failed To Insert";
                }
                return(result);
            }
        }
Example #11
0
        public User Login(string username, string password)
        {
            var context = new HotelDBContext();

            var _user = context.User.Where(x => x.UserName == username && x.Password == password).SingleOrDefault();

            return(_user);
        }
Example #12
0
        public List <HotelComment> GetHotelComment(int id)
        {
            var context = new HotelDBContext();

            var comments = context.HotelComment.Where(x => x.HotelId == id).ToList();

            return(comments);
        }
Example #13
0
        public List <HotelsViewModel> GetAll()
        {
            var context = new HotelDBContext();

            var _hotels = (from h in context.Hotel
                           join hs in context.HotelScore on h.Id equals hs.HotelId
                           join hi in context.HotelImage on h.Id equals hi.HotelId
                           select new HotelsViewModel {
                Id = h.Id, Name = h.Name, Description = h.Description, ScoreValue = hs.ScoreValue, ImagePath = hi.ImagePath
            });

            List <HotelsViewModel> _hotellist = _hotels.ToList();

            return(_hotellist);
        }
Example #14
0
        public HotelsViewModel GetHotelDetail(int id)
        {
            var context = new HotelDBContext();

            var balance = (from h in context.Hotel
                           join ha in context.HotelAddress on h.Id equals ha.HotelId
                           join hs in context.HotelScore on h.Id equals hs.HotelId
                           join hi in context.HotelImage on h.Id equals hi.HotelId
                           where h.Id == id
                           select new HotelsViewModel {
                Id = h.Id, Name = h.Name, Description = h.Description, AddressText = ha.AddressText, ScoreValue = hs.ScoreValue, ImagePath = hi.ImagePath
            }).SingleOrDefault();

            return(balance);
        }
Example #15
0
        public IEnumerable <RoomTypeModel> GetAllRoomType()
        {
            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                var data = _hotelEntities.RoomTypes.ToList();
                List <RoomTypeModel> roomList = new List <RoomTypeModel>();

                for (var i = 0; i < data.Count; i++)
                {
                    RoomTypeModel room = new RoomTypeModel();
                    room.Id       = data[i].Id;
                    room.RoomName = data[i].RoomName;
                    roomList.Add(room);
                }
                return(roomList);
            }
        }
Example #16
0
        public List <HotelsViewModel> GetSelectedHotels(string searchString)
        {
            var context = new HotelDBContext();

            var searchResult = (from h in context.Hotel
                                join hs in context.HotelScore on h.Id equals hs.HotelId
                                join hi in context.HotelImage on h.Id equals hi.HotelId
                                join ha in context.HotelAddress on h.Id equals ha.HotelId
                                select new HotelsViewModel {
                Id = h.Id, Name = h.Name, Description = h.Description, AddressText = ha.AddressText, ScoreValue = hs.ScoreValue, ImagePath = hi.ImagePath
            }).
                               Where(x => x.Name.Contains(searchString) || x.AddressText.Contains((searchString)));

            List <HotelsViewModel> searchHotels = searchResult.ToList();

            return(searchHotels);
        }
Example #17
0
        public IEnumerable <CountryModel> GetAllCountry()
        {
            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                var data = _hotelEntities.Countries.ToList();
                List <CountryModel> countryList = new List <CountryModel>();

                for (var i = 0; i < data.Count; i++)
                {
                    CountryModel country = new CountryModel();
                    country.Id          = data[i].Id;
                    country.CountryName = data[i].CountryName;
                    countryList.Add(country);
                }
                return(countryList);
            }
        }
Example #18
0
        public IEnumerable <AmenitiesModel> GetAllAmenities()
        {
            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                var data = _hotelEntities.Amenities.ToList();
                List <AmenitiesModel> amenityList = new List <AmenitiesModel>();

                for (var i = 0; i < data.Count; i++)
                {
                    AmenitiesModel amenities = new AmenitiesModel();
                    amenities.Id          = data[i].Id;
                    amenities.AmenityName = data[i].AmenityName;
                    amenityList.Add(amenities);
                }
                return(amenityList);
            }
        }
Example #19
0
        public HotelComment AddHotelComment(HotelComment hotelcomment)
        {
            var context = new HotelDBContext();

            try
            {
                if (hotelcomment.Id == 0)
                {
                    context.HotelComment.Add(hotelcomment);
                }
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(hotelcomment);
        }
Example #20
0
 public RoomTypeModel GetRoomById(int roomID)
 {
     using (HotelDBContext _hotelEntities = new HotelDBContext())
     {
         var data = _hotelEntities.RoomTypes.ToList();
         List <RoomTypeModel> roomList = new List <RoomTypeModel>();
         for (var i = 0; i < data.Count; i++)
         {
             RoomTypeModel model = new RoomTypeModel();
             model.Id        = data[i].Id;
             model.RoomName  = data[i].RoomName;
             model.Amenities = data[i].Amenities;
             roomList.Add(model);
         }
         RoomTypeModel getRoomData = roomList.SingleOrDefault(x => x.Id == roomID);
         return(getRoomData);
     }
 }
Example #21
0
        public ActionResult Search(SearchInput model)
        {
            HotelDBContext db = new HotelDBContext();

            if (ModelState.IsValid)
            {
                if ((model.ToDate.Date <= model.FromDate.Date) || (model.FromDate.Date < DateTime.Now.Date))
                {
                    ModelState.AddModelError("DateError", "Date is illegal, choose again");
                    TypeRoomModel   TrModel      = new TypeRoomModel();
                    List <TypeRoom> ListTypeRoom = TrModel.ListAll();
                    ViewBag.ListTypeRoom = new SelectList(ListTypeRoom, "TypeRoomID", "NameRoom");
                    return(View("Index", model));
                }
                Session["Search"] = model;
                RoomModel room     = new RoomModel();
                var       ListRoom = room.AvailableRoom(model.TypeRoomID, model.FromDate, model.ToDate);
                if (ListRoom.Count >= model.NumberOfRoom)
                {
                    List <RoomSelected> list = new List <RoomSelected>();
                    foreach (var item in ListRoom)
                    {
                        list.Add(new RoomSelected {
                            RoomID = item.RoomID, FromDate = model.FromDate, ToDate = model.ToDate, Checked = false
                        });
                    }
                    ViewBag.TypeRoom = db.TypeRooms.Find(model.TypeRoomID);
                    return(View(list));
                }
                else
                {
                    ViewBag.Message = "There is no room available";
                    return(View());
                }
            }
            else
            {
                TypeRoomModel   TrModel      = new TypeRoomModel();
                List <TypeRoom> ListTypeRoom = TrModel.ListAll();
                ViewBag.ListTypeRoom = new SelectList(ListTypeRoom, "TypeRoomID", "NameRoom");
                return(View("Index", model));
            }
        }
Example #22
0
        public IEnumerable <BookingModel> GetAllBooking()
        {
            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                var data = _hotelEntities.Bookings.ToList();
                List <BookingModel> bookingList = new List <BookingModel>();

                for (var i = 0; i < data.Count; i++)
                {
                    BookingModel booking = new BookingModel();
                    booking.Id             = data[i].Id;
                    booking.InvoiceNumber  = data[i].InvoiceNumber;
                    booking.BuyingPrice    = data[i].BuyingPrice;
                    booking.BuyingCurrency = data[i].BuyingCurrency;
                    bookingList.Add(booking);
                }
                return(bookingList);
            }
        }
Example #23
0
 public IEnumerable <PaymentViewModel> GetPaymentDetails()
 {
     using (HotelDBContext _hotelEntities = new HotelDBContext())
     {
         var data = _hotelEntities.Payments.ToList();
         List <PaymentViewModel> paymentList = new List <PaymentViewModel>();
         for (var i = 0; i < data.Count; i++)
         {
             PaymentViewModel paymentView = new PaymentViewModel();
             paymentView.Id        = data[i].Id;
             paymentView.Status    = data[i].Status;
             paymentView.BookingId = Convert.ToInt32(data[i].BookingId);
             BookingModel bookingModel = GetAllBooking().SingleOrDefault(x => x.Id == paymentView.BookingId);
             paymentView.InvoiceNumber  = bookingModel.InvoiceNumber;
             paymentView.BuyingPrice    = bookingModel.BuyingPrice;
             paymentView.BuyingCurrency = bookingModel.BuyingCurrency;
             paymentList.Add(paymentView);
         }
         return(paymentList);
     }
 }
Example #24
0
        public string DeleteHotel(int id)
        {
            string result = string.Empty;

            using (HotelDBContext _hotelEntities = new HotelDBContext())
            {
                try
                {
                    Hotel hotel = _hotelEntities.Hotels.Where(x => x.Id == id).FirstOrDefault <Hotel>();
                    _hotelEntities.Hotels.Remove(hotel);
                    _hotelEntities.SaveChanges();
                    result = "Record deleted";
                }
                catch (Exception)
                {
                    result = "Record failed to delete";
                }

                return(result);
            }
        }
 public ActionResult Check(Entity.AccountAdmin admin)
 {
     if (ModelState.IsValid)
     {
         Encode ec = new Encode();
         admin.Password = ec.EncodeSHA(admin.Password);
         using (HotelDBContext db = new HotelDBContext())
         {
             var UserDetail = db.AccountAdmins.Where(x => x.Username == admin.Username && x.Password == admin.Password).FirstOrDefault();
             if (UserDetail == null)
             {
                 ViewBag.Error = "Username or password incorrect !";
                 return(View("Index", admin));
             }
             else
             {
                 Session["UserID"] = admin.Username;
                 return(RedirectToAction("Index", "Home"));
             }
         }
     }
     ViewBag.Error = "Username or password incorrect !";
     return(View("Index", admin));
 }
Example #26
0
 public TypeRoomModel()
 {
     db = new HotelDBContext();
 }
Example #27
0
 public ClientRepository(HotelDBContext hotelDBContext)
 {
     this._hotelDBContext = hotelDBContext;
 }
Example #28
0
 public RoomRepository(HotelDBContext context)
 {
     this._context = context;
 }
Example #29
0
 public OrderModel()
 {
     db = new HotelDBContext();
 }
Example #30
0
 public UnitOfWorkEF(HotelDBContext dbContext)
 {
     this.dbContext = dbContext;
 }