Esempio n. 1
0
        public ActionResult Create()
        {
            ViewBag.Title = "Add new hotel";
            LoadData();
            var hotel = new EListHotel();

            return(View(hotel));
        }
Esempio 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));
        }
Esempio n. 3
0
        public ActionResult Update(EListHotel model)
        {
            //Kiểm tra xem alias đã tồn tại chưa
            var db         = new MyDbDataContext();
            var checkAlias =
                db.ListHotels.FirstOrDefault(
                    m => m.Alias == model.Alias && m.MenuID == model.MenuID && m.ID != model.ID);

            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 = db.ListHotels.FirstOrDefault(b => b.ID == model.ID);
                    if (hotel != null)
                    {
                        hotel.MenuID          = model.MenuID;
                        hotel.LocationId      = model.LocationId;
                        hotel.HotelName       = model.HotelName;
                        hotel.Alias           = model.Alias;
                        hotel.ImageHotel      = model.ImageHotel;
                        hotel.PriceFrom       = model.PriceFrom;
                        hotel.Description     = model.Description;
                        hotel.LocationHotel   = model.LocationHotel;
                        hotel.Status          = model.Status;
                        hotel.Index           = model.Index;
                        hotel.Star            = model.Star;
                        hotel.Address         = model.Address;
                        hotel.Home            = model.Home;
                        hotel.MetaKeyword     = model.MetaKeyword;
                        hotel.MetaDescription = model.MetaDescription;
                        hotel.Facility        = model.Facility;
                        hotel.Content         = model.Content;
                        hotel.Note            = model.Note;

                        db.SubmitChanges();

                        //xóa gallery
                        db.HotelGalleries.DeleteAllOnSubmit(db.HotelGalleries.Where(a => a.HotelId == hotel.ID).ToList());
                        //Thêm gallery mới
                        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"] = "Update successful.";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception exception)
                {
                    LoadData();
                    TempData["Messages"] = "Error: " + exception.Message;
                    return(View());
                }
            }
            LoadData();
            return(View(model));
        }
Esempio n. 4
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());
            }
        }