Ejemplo n.º 1
0
 public static ShowDetailHotel Detail_Hotel(int id)
 {
     using (var db = new MyDbDataContext())
     {
         ListHotel           listHotel      = db.ListHotels.FirstOrDefault(a => a.ID == id && a.Status) ?? new ListHotel();
         Room                room           = db.Rooms.FirstOrDefault(a => a.ID == id && a.Status) ?? new Room();
         List <HotelGallery> hotelGalleries = db.HotelGalleries.Where(a => a.HotelId == listHotel.ID).ToList();
         List <ListHotel>    listHotels     = db.ListHotels.Where(a => a.Status).OrderBy(a => a.Index).ToList();
         List <Room>         rooms          = db.Rooms.Where(a => a.HotelId == listHotel.ID).ToList();
         List <RoomGallery>  roomGalleries  = db.RoomGalleries.Where(a => a.RoomGalleryId == room.ID).ToList();
         foreach (var item in listHotels)
         {
             item.MenuAlias = item.Menu.Alias;
         }
         ShowDetailHotel showDetailHotel = new ShowDetailHotel()
         {
             Title          = listHotel.Menu.Title,
             AliasMenu      = listHotel.Menu.Alias,
             ListHotel      = listHotel,
             ListHotels     = listHotels,
             HotelGalleries = hotelGalleries,
             Rooms          = rooms,
             RoomGalleries  = roomGalleries,
         };
         return(showDetailHotel);
     }
 }
Ejemplo n.º 2
0
        public ActionResult Update(int id)
        {
            var       db          = new MyDbDataContext();
            ListHotel detailHotel = db.ListHotels.FirstOrDefault(a => a.ID == id);

            if (detailHotel == null)
            {
                TempData["Messages"] = "Hotel is not exist";
                return(RedirectToAction("Index"));
            }
            ViewBag.Title = "Update Hotel";
            LoadData();
            EListHotel hotel = new EListHotel
            {
                ID              = detailHotel.ID,
                MenuID          = detailHotel.MenuID,
                LocationId      = detailHotel.LocationId,
                HotelName       = detailHotel.HotelName,
                Alias           = detailHotel.Alias,
                ImageHotel      = detailHotel.ImageHotel,
                PriceFrom       = (float)detailHotel.PriceFrom,
                Description     = detailHotel.Description,
                LocationHotel   = detailHotel.LocationHotel,
                Status          = detailHotel.Status,
                Index           = (int)detailHotel.Index,
                Star            = detailHotel.Star,
                Address         = detailHotel.Address,
                Home            = detailHotel.Home,
                MetaKeyword     = detailHotel.MetaKeyword,
                MetaDescription = detailHotel.MetaDescription,
                Facility        = detailHotel.Facility,
                Content         = detailHotel.Content,
                Note            = detailHotel.Note,
            };

            //lấy danh sách hình ảnh

            hotel.EGalleryITems = db.HotelGalleries.Where(a => a.HotelId == detailHotel.ID).Select(a => new EListHotel.EGalleryITem
            {
                Image = a.ImageLage
            }).ToList();

            return(View(hotel));
        }
Ejemplo n.º 3
0
        public ActionResult Create(EListHotel model)
        {
            //End check
            using (var db = new MyDbDataContext())
            {
                //Kiểm tra xem alias thuộc hotel này đã tồn tại chưa
                var checkAlias =
                    db.ListHotels.FirstOrDefault(
                        m => m.Alias == model.Alias && m.MenuID == model.MenuID);
                if (checkAlias != null)
                {
                    ModelState.AddModelError("AliasRoom", "Hotel is exist.");
                }
                //Kiểm tra xem đã chọn đến chuyên mục con cuối cùng chưa
                if (db.Menus.Any(a => a.ParentID == model.MenuID))
                {
                    ModelState.AddModelError("MenuId", "You haven't selected the last tour category");
                }
                if (!string.IsNullOrEmpty(model.HotelName))
                {
                    model.Alias = StringHelper.ConvertToAlias(model.HotelName);
                }
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(model.Alias))
                    {
                        model.Alias = StringHelper.ConvertToAlias(model.Alias);
                    }
                    try
                    {
                        var hotel = new ListHotel
                        {
                            CreateDate      = DateTime.Now,
                            MenuID          = model.MenuID,
                            LocationId      = model.LocationId,
                            HotelName       = model.HotelName,
                            Alias           = model.Alias,
                            ImageHotel      = model.ImageHotel,
                            PriceFrom       = model.PriceFrom,
                            Description     = model.Description,
                            Address         = model.Address,
                            Status          = model.Status,
                            Index           = model.Index,
                            Star            = model.Star,
                            Home            = model.Home,
                            LocationHotel   = model.LocationHotel,
                            MetaKeyword     = model.MetaKeyword,
                            MetaDescription = model.MetaDescription,
                            Facility        = model.Facility,
                            Content         = model.Content,
                            Note            = model.Note,
                        };

                        db.ListHotels.InsertOnSubmit(hotel);
                        db.SubmitChanges();

                        //Thêm hình ảnh cho tour
                        if (model.EGalleryITems != null)
                        {
                            foreach (EListHotel.EGalleryITem itemGallery in model.EGalleryITems)
                            {
                                var gallery = new HotelGallery
                                {
                                    ImageLage  = itemGallery.Image,
                                    ImageThump = ReturnSmallImage.GetImageSmall(itemGallery.Image),
                                    HotelId    = hotel.ID,
                                };
                                db.HotelGalleries.InsertOnSubmit(gallery);
                            }
                            db.SubmitChanges();
                        }

                        TempData["Messages"] = "Insert successfull.";
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception exception)
                    {
                        LoadData();
                        TempData["Messages"] = "Error: " + exception.Message;
                        return(View());
                    }
                }
                LoadData();
                return(View());
            }
        }