Exemplo n.º 1
0
        // Page d'accueil de l'application
        public ActionResult Index()
        {
            // Le controller récupère la liste de tous les hôtels proposés par Valais Booking
            var hotels = HotelManager.GetAllHotels();
            List <ListHotelsVM> list = new List <ListHotelsVM>();

            // Pour chaque hôtel, le controller récupère toutes les photos qui correspondent aux chambres de l'hôtel
            foreach (var item in hotels)
            {
                // Une fonction "DISTINCT" est utilisée pour récupérer seulement les photos différentes
                // Elle est utilisée uniquement car la BDD contient souvent les mêmes URL
                IEnumerable <Picture> pics = PictureManager.GetAllPictures(item.IdHotel);
                List <string>         urls = pics.Select(pic => pic.Url).Distinct().ToList();

                ListHotelsVM hotel = new ListHotelsVM
                {
                    IdHotel      = item.IdHotel,
                    Name         = item.Name,
                    Description  = item.Description,
                    Location     = item.Location,
                    Category     = item.Category,
                    HasWifi      = item.HasWifi,
                    HasParking   = item.HasParking,
                    Phone        = item.Phone,
                    Email        = item.Email,
                    Website      = item.Website,
                    PicturesUrls = urls
                };

                list.Add(hotel);
            }

            return(View(list));
        }
Exemplo n.º 2
0
        public void GetAllHotelsTest()
        {
            HotelManager target = new HotelManager();
            List <Hotel> actual = target.GetAllHotels();

            Assert.AreEqual(actual.Count >= 1, true);
        }
        public async Task <ActionResult <HotelManager> > PostHotelManager(HotelManager hotelManager)
        {
            _context.HotelManager.Add(hotelManager);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetHotelManager", new { id = hotelManager.id }, hotelManager));
        }
Exemplo n.º 4
0
        private void ResetHotelDataSet()
        {
            HotelManager hm      = new HotelManager();
            DataSet      hotelDS = hm.GetAllHotels();

            Session["HOTELDS"] = hotelDS;
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <HotelAdvisorContext, Configuration>());
            //CreateHotel();

            // User u = new User{Email="*****@*****.**", Password="******" };
            // UserManager um = new UserManager();
            //um.CreateUser(u);

            //User u1 = new User { Email = "*****@*****.**", Password = "******" };
            //um.CreateUser(u1);

            //User user = um.FindUserById(1);
            //Console.WriteLine("User id:{0}, email: {1}", user.Id, user.Email);
            //Console.ReadKey();

            //var c1 = new Comment{Text = "Odlican hotel!", Rating = 4, UserId = 1, HotelId=1};
            //var c2 = new Comment{Text = "Dobar bazen!", Rating = 2, UserId = 1, HotelId=2};
            //var c3 = new Comment{Text = "Odlican hotel!", Rating = 5, UserId = 2, HotelId=1};
            //CommentManager cm = new CommentManager();
            //cm.CreateComment(c1);
            //cm.CreateComment(c2);
            //cm.CreateComment(c3);

            HotelManager hm = new HotelManager();
            decimal      r  = hm.FindHotelAverageRating(1);

            Console.WriteLine("rating " + r);
            Console.ReadKey();
        }
Exemplo n.º 6
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                HotelManager hm    = new HotelManager();
                Hotel        hotel = new Hotel();
                ICityManager cm    = (ICityManager)BusinessObjectManager.GetCityManager();

                hotel.HotelName   = txtHotelName.Text;
                hotel.Address     = txtAddress.Text;
                hotel.City        = cm.GetCityById(Convert.ToInt64(dpCity.SelectedValue));
                hotel.CityID      = Convert.ToInt32(dpCity.SelectedValue);
                hotel.BriefNote   = txtBrief.Text;
                hotel.Email       = txtEMail.Text;
                hotel.ContactNo   = txtContact.Text;
                hotel.Pincode     = txtPincode.Text;
                hotel.StarRanking = Convert.ToInt32(dpStarRanking.SelectedValue);
                hotel.PhotoUrl    = txtPhoto.Text;
                hotel.WebsiteURL  = txtWebsite.Text;

                hm.SaveHotel(hotel);

                //Resetting the session to invalidate the hotels
                Session["HOTELDS"] = null;

                Response.Redirect("~/Admin/ViewHotel.aspx");
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
Exemplo n.º 7
0
 protected void btnEdit_Click(object sender, EventArgs e)
 {
     try
     {
         HotelManager hm       = new HotelManager();
         RoomType     roomtype = new RoomType();
         string       typeid   = Request.QueryString.Get("typeid");
         roomtype.TypeId      = Int32.Parse(typeid);
         roomtype.Title       = txtTitle.Text;
         roomtype.Code        = txtCode.Text;
         roomtype.Description = txtDescription.Text;
         roomtype.IsActive    = chkIsActive.Checked;
         bool status = hm.EditRoomTypes(roomtype, Int32.Parse(typeid));
         if (status == true)
         {
             lblUpdateResult.ForeColor = System.Drawing.Color.Green;
             lblUpdateResult.Text      = "Updated successfully";
         }
         else
         {
             lblUpdateResult.ForeColor = System.Drawing.Color.Red;
             lblUpdateResult.Text      = "Updatation failed";
         }
     }
     catch (HotelManagerException ex)
     {
         lblUpdateResult.Text = ex.Message;
     }
 }
Exemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["HotelID"] == null)                 //查询字符串为空
                {
                    Response.Write("<script>alert('酒店ID为空!');location.href='Default.aspx';</script>");
                    Response.End();
                }
                else
                {
                    try
                    {
                        hotelID = int.Parse(Request.QueryString["HotelID"]);
                    }
                    catch
                    {
                        Response.Write("<script>alert('酒店ID不为数字!');location.href='Default.aspx';</script>");
                        Response.End();
                    }

                    try
                    {
                        var hotel = HotelManager.GetHotelByID(hotelID);
                        Bind(hotel);
                    }
                    catch
                    {
                        Response.Write("<script>alert('酒店ID不正确!');location.href='Default.aspx';</script>");
                        Response.End();
                    }
                }
            }
        }
Exemplo n.º 9
0
        public ActionResult Index(int IdRoom)
        {
            OneRoomVM RoomSelected = new OneRoomVM();

            var InfoRoom = RoomManager.GetRoomById(IdRoom);

            if (InfoRoom != null)
            {
                RoomSelected.room    = InfoRoom;
                RoomSelected.hotel   = HotelManager.GetHotelById(InfoRoom.IdHotel);
                RoomSelected.picture = PictureManager.getAllPictureByIdroom(IdRoom);

                int    priceIncrease = RoomManager.countRoomByIdHotel(InfoRoom.IdHotel, (DateTime)Session["CheckInWanted"], (DateTime)Session["CheckOutWanted"], (String)Session["LocationHotel"], (int)Session["nbCustomer"]);
                double price         = (double)InfoRoom.Price;

                if (priceIncrease.Equals(1))
                {
                    price = price + (price * 0.2);
                }
                Session["priceIncrease"] = priceIncrease;

                RoomSelected.room.Price = (decimal)price;

                return(View(RoomSelected));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 10
0
        public async Task <JsonResult> GetDineForPrinting(int hotelId, string dineId, List <int> dineMenuIds)
        {
            string connStr = await YummyOnlineManager.GetHotelConnectionStringById(hotelId);

            var tHotel = new YummyOnlineManager().GetHotelForPrintingById(hotelId);

            Task <Dine> tDine = null;

            if (dineId == "00000000000000")
            {
                tDine = generateTestDine();
            }
            else
            {
                tDine = new HotelManager(connStr).GetDineForPrintingById(dineId, dineMenuIds);
            }

            var tPrinterFormat = new HotelManager(connStr).GetPrinterFormatForPrinting();
            var tUser          = new YummyOnlineManager().GetUserForPrintingById((await tDine).UserId);

            return(Json(new DineForPrinting {
                Hotel = await tHotel,
                Dine = await tDine,
                User = await tUser,
                PrinterFormat = await tPrinterFormat
            }));
        }
Exemplo n.º 11
0
        private void PrintEmptyApartmentCount()
        {
            Console.Clear();
            Console.WriteLine("===== Empty Apartments =====");

            Console.WriteLine("Input Booking From (mm/dd/yyyy): ");
            string from = Console.ReadLine();

            if (!DateTime.TryParse(from, out DateTime resultFrom))
            {
                this.PrintTryAgain();
                return;
            }

            Console.WriteLine("Input Booking Till (mm/dd/yyyy): ");
            string till = Console.ReadLine();

            if (!DateTime.TryParse(till, out DateTime resultTill))
            {
                this.PrintTryAgain();
                return;
            }

            Console.WriteLine($"Empty apartments count: {HotelManager.EmptyApartmentCountForDate(resultFrom, resultTill)}");
            Console.WriteLine("========================");
        }
Exemplo n.º 12
0
        public async Task <JsonResult> GetMenuInfos()
        {
            var t1 = new HotelManager(CurrHotel.ConnectionString).GetFormatedMenuClasses();
            var t2 = new HotelManager(CurrHotel.ConnectionString).GetFormatedMenus();
            var t3 = new HotelManager(CurrHotel.ConnectionString).GetFormatedMenuOnSales();
            var t4 = new HotelManager(CurrHotel.ConnectionString).GetFormatedMenuSetMeals();
            var t5 = new HotelManager(CurrHotel.ConnectionString).GetFormatedPayKinds(new List <PayKindType> {
                PayKindType.Online, PayKindType.Other
            });
            var t6        = new HotelManager(CurrHotel.ConnectionString).GetHotelConfig();
            var t7        = new HotelManager(CurrHotel.ConnectionString).GetTimeDiscounts();
            var t8        = new HotelManager(CurrHotel.ConnectionString).GetVipDiscounts();
            var currHotel = await new YummyOnlineManager().GetHotelById(CurrHotel.Id);

            var result = new {
                MenuClasses     = await t1,
                Menus           = await t2,
                MenuOnSales     = await t3,
                MenuSetMeals    = await t4,
                PayKinds        = await t5,
                DiscountMethods = new {
                    TimeDiscounts = await t7,
                    VipDiscounts  = await t8
                },
                Hotel = DynamicsCombination.CombineDynamics(await t6, new {
                    currHotel.Name,
                    currHotel.Address,
                    currHotel.Tel,
                    currHotel.OpenTime,
                    currHotel.CloseTime
                })
            };

            return(Json(result));
        }
Exemplo n.º 13
0
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            HotelManager hm      = new HotelManager();
            HotelRoom    hotelRm = new HotelRoom();

            hotelRm.RoomType = new RoomType();

            int hotelId = Int32.Parse(Request.QueryString["hotelid"]);

            hotelRm.RoomType.Title  = txtTitle.Text;
            hotelRm.RoomType.TypeId = Int32.Parse(txtTypeId.Text);
            hotelRm.CostPerDay      = Convert.ToSingle(txtCostPerDay.Text);
            hotelRm.NoOfRooms       = Int32.Parse(txtNoOfRooms.Text);
            bool edit = hm.EditHotelRooms(hotelRm, hotelId);

            if (edit == true)
            {
                updtmsg.Text = "Updated successfully";
            }
            else
            {
                updtmsg.Text = "Update not successful";
            }

            txtTypeId.Text = txtTitle.Text = txtCostPerDay.Text = txtNoOfRooms.Text = string.Empty;
        }
Exemplo n.º 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HotelManager hm = new HotelManager();
                try
                {
                    string  hotelId = Request.QueryString["hotelid"];
                    string  typeId  = Request.QueryString["typeid"];
                    DataSet ds      = hm.GetHotelsById(Convert.ToInt64(hotelId));

                    txtHotelName.Text = ds.Tables[0].Rows[0]["HotelName"].ToString();
                    ds = hm.GetHotelRooms(Convert.ToInt32(hotelId));

                    foreach (DataRow item in ds.Tables[0].Rows)
                    {
                        if (item["TypeId"].ToString().Equals(typeId))
                        {
                            txtTypeId.Text     = item[1].ToString();
                            txtTitle.Text      = item[2].ToString();
                            txtCostPerDay.Text = item[3].ToString();
                            txtNoOfRooms.Text  = item[4].ToString();
                        }
                    }
                }
                catch (HotelManagerException ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 15
0
        private async void RellenarDropdownHotelRelacionado()
        {
            DropDownList_HotelRelacion.Items.Clear();

            // Trae la lista de hoteles disponibles de la base de datos.
            IEnumerable <Models.Hotel> iEnumerable_hoteles = new ObservableCollection <Models.Hotel>();
            HotelManager hotelManager = new HotelManager();

            iEnumerable_hoteles = await hotelManager.ObtenerHoteles(VG.usuarioActual.CadenaToken);

            List <Models.Hotel> lista_hoteles = iEnumerable_hoteles.ToList();

            if (lista_hoteles.Count > 0)
            { // Rellena el dropdown con los hoteles disponibles.
                lista_hoteles.Reverse();
                for (int i = 0; i < lista_hoteles.Count(); i++)
                {
                    DropDownList_HotelRelacion.Items
                    .Insert(0, new ListItem(lista_hoteles[i].HOT_NOMBRE
                                            , "" + lista_hoteles[i].HOT_CODIGO));
                }
            }

            // Coloca la opcion "Seleccionar" al inicio del dropdown para obligar al usuario a seleccionar
            // un hotel.
            DropDownList_HotelRelacion.Items.Insert(0, new ListItem("Seleccionar", "seleccionar"));
        }
Exemplo n.º 16
0
        private void ShowRoomTypesGridView()
        {
            HotelManager hotelManager = new HotelManager();

            RoomTypesGridView.DataSource = hotelManager.GetRoomTypes();
            RoomTypesGridView.DataBind();
        }
Exemplo n.º 17
0
        protected void Save_Click_Click(object sender, EventArgs e)
        {
            RoomType roomtype = new RoomType();

            roomtype.Title       = TxtTitle.Text;
            roomtype.Description = TxtDesc.Text;
            roomtype.Code        = Txtcode.Text;
            roomtype.IsActive    = CheckActive.Checked;
            HotelManager hotelmanager = new HotelManager();

            try
            {
                if (hotelmanager.SaveRoomTypes(roomtype))
                {
                    Button2_Click(sender, e);
                    lblErrors.ForeColor = System.Drawing.Color.Green;
                    lblErrors.Text      = "Hotel Type Added successfully";
                }
                else
                {
                    lblErrors.ForeColor = System.Drawing.Color.Red;
                    lblErrors.Text      = "Hotel Type already exists";
                }
            }
            catch (HotelManagerException ex)
            {
                throw ex;
            }
        }
Exemplo n.º 18
0
 // GET: Book
 public ActionResult Index(BookVM bookVM = null)
 {
     Session["filter"] = false;
     bookVM.Hotels = HotelManager.GetHotelsByDateLocationAndNbPerson(bookVM.Checkin, bookVM.Checkout, bookVM.Location, bookVM.NbPerson, 0, 5, null, null);
     Session["bookVM"] = bookVM;
     return View(bookVM);
 }
Exemplo n.º 19
0
        public async Task <JsonResult> CreateHotel(int hotelId, string databaseName)
        {
            // 创建空数据库
            OriginSql originSql = new OriginSql(new YummyOnlineContext().Database.Connection.ConnectionString);
            var       result    = await originSql.CreateDatabase(databaseName);

            if (!result.Succeeded)
            {
                return(Json(new JsonError(result.Message)));
            }
            // 总数据库记录连接字符串等信息
            await YummyOnlineManager.CreateHotel(hotelId, databaseName);

            // 新数据库写入所有表格等架构
            Hotel newHotel = await YummyOnlineManager.GetHotelById(hotelId);

            originSql = new OriginSql(newHotel.AdminConnectionString);
            result    = await originSql.InitializeHotel();

            if (!result.Succeeded)
            {
                return(Json(new JsonError(result.Message)));
            }

            // 新数据库初始化
            string staffId = await YummyOnlineManager.GetHotelAdminId(hotelId);

            HotelManager hotelManager = new HotelManager(newHotel.AdminConnectionString);
            await hotelManager.InitializeHotel(hotelId, staffId);

            return(Json(new JsonSuccess()));
        }
Exemplo n.º 20
0
        // GET: Hotel
        public ActionResult Index()
        {
            HotelManager manager = new HotelManager();
            List <HotelDetailsViewModel> model = manager.GetHotels();

            return(View(model));
        }
Exemplo n.º 21
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            HotelManager hm    = new HotelManager();
            Hotel        hotel = new Hotel();
            ICityManager cm    = (ICityManager)BusinessObjectManager.GetCityManager();

            hotel.HotelId     = Convert.ToInt64(txtHotelId.Text);
            hotel.HotelName   = txtHotelName.Text;
            hotel.Address     = txtAddress.Text;
            hotel.City        = cm.GetCityById(Convert.ToInt64(dpCity.SelectedValue));
            hotel.CityID      = Convert.ToInt32(dpCity.SelectedValue);
            hotel.BriefNote   = txtBrief.Text;
            hotel.Email       = txtEMail.Text;
            hotel.ContactNo   = txtContact.Text;
            hotel.Pincode     = txtPincode.Text;
            hotel.StarRanking = Convert.ToInt32(dpStarRanking.SelectedValue);
            hotel.PhotoUrl    = txtPhoto.Text;
            hotel.WebsiteURL  = txtWebsite.Text;

            hm.UpdateHotel(hotel);

            ResetHotelDataSet();

            Response.Redirect("~/Admin/ViewHotel.aspx");
        }
Exemplo n.º 22
0
        public ActionResult Edit(HotelViewModel model)
        {
            if (ModelState.IsValid)
            {
                var fileName = string.Empty;

                if (model.Image != null)
                {
                    // extract only the fielname
                    fileName = Path.GetFileName(model.Image.FileName);
                    // store the file inside ~/Content/HotelImages folder
                    var path = Path.Combine(Server.MapPath("~/Content/HotelImages"), fileName);
                    model.Image.SaveAs(path);
                }

                HotelManager manager = new HotelManager();
                Hotel        hotel   = new Hotel();
                hotel.Id          = model.Id;
                hotel.Name        = model.Name;
                hotel.Description = model.Description;
                hotel.City        = model.City;
                hotel.Address     = model.Address;
                hotel.HouseNumber = model.HouseNumber;
                hotel.IsActive    = model.IsActive;
                hotel.Image       = string.IsNullOrEmpty(fileName) ? null : "/Content/HotelImages/" + fileName;

                manager.Edit(hotel);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 23
0
        public async Task <JsonResult> GetDineDailyCount()
        {
            List <dynamic> list   = new List <dynamic>();
            List <Hotel>   hotels = await YummyOnlineManager.GetHotels();

            foreach (Hotel h in hotels)
            {
                if (h.ConnectionString == null)
                {
                    continue;
                }
                List <dynamic> dailyCount   = new List <dynamic>();
                HotelManager   hotelManager = new HotelManager(h.ConnectionString);
                for (int i = -30; i <= 0; i++)
                {
                    DateTime t     = DateTime.Now.AddDays(i);
                    int      count = await hotelManager.GetDineCount(t);

                    dailyCount.Add(new {
                        DateTime = t,
                        Count    = count
                    });
                }

                list.Add(new {
                    HotelName  = h.Name,
                    DailyCount = dailyCount
                });
            }

            return(Json(list));
        }
Exemplo n.º 24
0
        public ActionResult <HotelManager> PutHotelManager(HotelManager hotelManager)
        {
            var hotelManagerDB = _context.HotelManager.FirstOrDefault(x => x.Id == hotelManager.Id);

            if (hotelManagerDB == null)
            {
                return(BadRequest("Hotel manager by given ID does not exist in database."));
            }

            hotelManagerDB.Name    = hotelManager.Name;
            hotelManagerDB.Surname = hotelManager.Surname;
            hotelManagerDB.PIN     = hotelManager.PIN;

            _context.Entry(hotelManagerDB).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
                return(Ok("Hotel manager change data has succeed."));
            }
            catch (Exception)
            {
                return(BadRequest("Database update has failed."));
            }
        }
        public ActionResult Details(int id)
        {
            HotelManager manager = new HotelManager();
            var          model   = manager.GetHotelDetails(id);

            return(View(model));
        }
Exemplo n.º 26
0
        public void GivenStartandEndDates_ShouldReturn_CheapestHotelForWeekendandWeekdaysRATINGS()
        {
            try
            {
                HotelManager manager = new HotelManager();
                manager.CreateHotelList();

                DateTime startDate = Convert.ToDateTime("11Sep2020");
                DateTime endDate   = Convert.ToDateTime("12Sep2020");

                Dictionary <Hotel, int> actualCheapHotelList = new Dictionary <Hotel, int>();
                actualCheapHotelList = manager.FindCheapestBestRatedHotel(startDate, endDate, "Regular");

                Dictionary <Hotel, int> expectedCheapHotelList = new Dictionary <Hotel, int>();
                expectedCheapHotelList.Add(new Hotel("Lakewood", 110, 90, 80, 80, 3), 200);
                expectedCheapHotelList.Add(new Hotel("Bridgewood", 160, 120, 100, 40, 4), 200);

                //bool isEqual = actualCheapHotelList.Equals(expectedCheapHotelList);
                //    //manager.ContentEquals<Hotel, int>(actualCheapHotelList, expectedCheapHotelList);
                //Assert.AreEqual(isEqual, true);

                CollectionAssert.AreEquivalent(expectedCheapHotelList, actualCheapHotelList);
            }
            catch (HotelException e)
            {
                Assert.AreEqual(e.Message, "Invalid Customer Type");
            }
        }
        public async Task <IActionResult> PutHotelManager(int id, HotelManager hotelManager)
        {
            if (id != hotelManager.id)
            {
                return(BadRequest());
            }

            _context.Entry(hotelManager).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemplo n.º 28
0
        // GET: Hotel
        public ActionResult Index()
        {
            List <Hotel> all = HotelManager.GetHotels();

            all.ToList();
            return(View(all));
        }
Exemplo n.º 29
0
        public async void GetHotelByIdInDb()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>()
                                                           .UseInMemoryDatabase("SavingHotelInDb")
                                                           .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                HotelManager service = new HotelManager(context);

                Hotel testHotel = new Hotel();
                testHotel.ID            = 3;
                testHotel.Name          = "Test Hotel";
                testHotel.Phone         = "000-000-0000";
                testHotel.StreetAddress = "0000 Test Stree";
                testHotel.State         = "WA";

                await service.CreateHotelAsync(testHotel);

                await service.GetHotelAsync(3);

                Hotel result = await context.Hotel.FirstOrDefaultAsync(x => x.Name == testHotel.Name);

                Assert.Equal("Test Hotel", result.Name);
            }
        }
Exemplo n.º 30
0
        public async Task <JsonResult> PrintCompleted(string dineId)
        {
            await OrderManager.PrintCompleted(dineId);

            await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Success, $"PrintCompleted DineId: {dineId}");

            return(Json(new JsonSuccess()));
        }