示例#1
0
        public ActionResult Create(ETour model)
        {
            using (var db = new MyDbDataContext())
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(model.Alias))
                    {
                        model.Alias = StringHelper.ConvertToAlias(model.Title);
                    }
                    try
                    {
                        var tour = new Tour
                        {
                            MenuID          = model.MenuID,
                            ActivitiesID    = model.ActivitisID,
                            Title           = model.Title,
                            Alias           = model.Alias,
                            Image           = model.Image,
                            Index           = 0,
                            Description     = model.Description,
                            MetaTitle       = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle,
                            MetaDescription =
                                string.IsNullOrEmpty(model.MetaDescription) ? model.Title : model.MetaDescription,
                            Status    = model.Status,
                            Price     = model.Price,
                            Location  = model.Location,
                            PriceSale = model.PriceSale,
                            Hot       = model.Hot,
                            Deal      = model.Deal,
                            Like      = model.Like,
                            //StatusPrice = model.StatusPrice,
                            TourOther    = model.TourOther,
                            TourIncluded = model.TourIncluded,
                            TourExcluded = model.TourExcluded,
                        };

                        db.Tours.InsertOnSubmit(tour);
                        db.SubmitChanges();

                        //Thêm tabHotel
                        if (model.TabHotels != null)
                        {
                            foreach (TabHotel item in model.TabHotels)
                            {
                                var tabTour = new TabHotel
                                {
                                    TourID        = tour.ID,
                                    TitleTabHotel = item.TitleTabHotel,
                                    ContentHotel  = item.ContentHotel,
                                };

                                db.TabHotels.InsertOnSubmit(tabTour);
                            }
                            db.SubmitChanges();
                        }

                        if (model.Theme != null)
                        {
                            for (int i = 0; i < model.Theme.Length; i++)
                            {
                                var tabTheme = new ThemesMenu
                                {
                                    TourID = tour.ID,
                                    MenuID = int.Parse(model.Theme[i]),
                                    Index  = 0
                                };
                                db.ThemesMenus.InsertOnSubmit(tabTheme);
                                db.SubmitChanges();
                            }
                        }

                        //Thêm hình ảnh cho tour
                        if (model.EGalleryITems != null)
                        {
                            foreach (EGalleryITem itemGallery in model.EGalleryITems)
                            {
                                var gallery = new TourGallery
                                {
                                    LargeImage = itemGallery.Image,
                                    SmallImage = ReturnSmallImage.GetImageSmall(itemGallery.Image),
                                    TourID     = tour.ID,
                                };
                                db.TourGalleries.InsertOnSubmit(gallery);
                            }
                            db.SubmitChanges();
                        }
                        //Thêm tabtour
                        if (model.TabTours != null)
                        {
                            foreach (TabTour itemTabTour in model.TabTours)
                            {
                                var tabTour = new TabTour
                                {
                                    TourID   = tour.ID,
                                    TitleTab = itemTabTour.TitleTab,
                                    Content  = itemTabTour.Content,
                                    Price    = itemTabTour.Price,
                                };

                                db.TabTours.InsertOnSubmit(tabTour);
                            }
                            db.SubmitChanges();
                        }

                        TempData["Messages"] = "Successful";
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception exception)
                    {
                        LoadData();
                        LoadDataActivities();
                        ViewBag.Messages = "Error: " + exception.Message;
                        return(View(model));
                    }
                }
                LoadData();
                LoadDataActivities();
                return(View(model));
            }
        }
示例#2
0
        public ActionResult Update(ETour model)
        {
            //Kiểm tra xem alias thuộc tour này đã tồn tại chưa
            var db = new MyDbDataContext();

            //Kiểm tra xem đã chọn đến chuyên mục con cuối cùng chưa
            //var check = db.Menus.Where(a => a.ParentID == model.ID).ToList();
            //if (db.Menus.Any(a => a.ParentID == model.ID))
            //{
            //    ModelState.AddModelError("MenuId", "Vui lòng chọn đến chuyên mục tour con cuối cùng");
            //}

            if (ModelState.IsValid)
            {
                try
                {
                    Tour tour = db.Tours.FirstOrDefault(b => b.ID == model.ID);
                    if (tour != null)
                    {
                        tour.MenuID       = model.MenuID;
                        tour.ActivitiesID = model.ActivitisID;
                        tour.Location     = model.Location;
                        //tour.StatusPrice = model.StatusPrice;
                        tour.Like            = model.Like;
                        tour.Deal            = model.Deal;
                        tour.Title           = model.Title;
                        tour.Alias           = model.Alias;
                        tour.Image           = model.Image;
                        tour.Description     = model.Description;
                        tour.MetaTitle       = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle;
                        tour.MetaDescription = string.IsNullOrEmpty(model.MetaDescription)
                            ? model.Title
                            : model.MetaDescription;
                        tour.Status       = model.Status;
                        tour.Hot          = model.Hot;
                        tour.Price        = model.Price;
                        tour.PriceSale    = model.PriceSale;
                        tour.TourOther    = model.TourOther;
                        tour.TourIncluded = model.TourIncluded;
                        tour.TourExcluded = model.TourExcluded;
                        db.SubmitChanges();

                        //xóa gallery cho tour
                        db.TourGalleries.DeleteAllOnSubmit(db.TourGalleries.Where(a => a.TourID == tour.ID).ToList());
                        //Thêm hình ảnh cho tour
                        if (model.EGalleryITems != null)
                        {
                            foreach (EGalleryITem itemGallery in model.EGalleryITems)
                            {
                                var gallery = new TourGallery
                                {
                                    LargeImage = itemGallery.Image,
                                    SmallImage = ReturnSmallImage.GetImageSmall(itemGallery.Image),
                                    TourID     = tour.ID,
                                };
                                db.TourGalleries.InsertOnSubmit(gallery);
                            }
                            db.SubmitChanges();
                        }
                        //xóa danh sách tabtour
                        db.TabTours.DeleteAllOnSubmit(db.TabTours.Where(a => a.TourID == tour.ID).ToList());
                        db.ThemesMenus.DeleteAllOnSubmit(db.ThemesMenus.Where(a => a.TourID == tour.ID).ToList());
                        if (model.Theme != null)
                        {
                            for (int i = 0; i < model.Theme.Length; i++)
                            {
                                var tabTheme = new ThemesMenu
                                {
                                    TourID = tour.ID,
                                    MenuID = int.Parse(model.Theme[i]),
                                    Index  = 0
                                };
                                db.ThemesMenus.InsertOnSubmit(tabTheme);
                                db.SubmitChanges();
                            }
                        }

                        //Thêm tabtour
                        if (model.TabTours != null)
                        {
                            foreach (TabTour itemTabTour in model.TabTours)
                            {
                                var tabTour = new TabTour
                                {
                                    TourID   = tour.ID,
                                    TitleTab = itemTabTour.TitleTab,
                                    Content  = itemTabTour.Content,
                                    Price    = itemTabTour.Price
                                };

                                db.TabTours.InsertOnSubmit(tabTour);
                            }
                            db.SubmitChanges();
                        }
                        db.TabHotels.DeleteAllOnSubmit(db.TabHotels.Where(a => a.TourID == tour.ID).ToList());
                        if (model.TabHotels != null)
                        {
                            foreach (TabHotel item in model.TabHotels)
                            {
                                var tabTour = new TabHotel
                                {
                                    TourID        = tour.ID,
                                    TitleTabHotel = item.TitleTabHotel,
                                    ContentHotel  = item.ContentHotel,
                                };

                                db.TabHotels.InsertOnSubmit(tabTour);
                            }
                            db.SubmitChanges();
                        }

                        TempData["Messages"] = "Successful";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception exception)
                {
                    LoadData();
                    LoadDataActivities();
                    ViewBag.Messages = "Error: " + exception.Message;
                    return(View());
                }
            }
            LoadData();
            LoadDataActivities();
            return(View(model));
        }
示例#3
0
        public ActionResult Create(ETour model)
        {
            using (var db = new MyDbDataContext())
            {
                //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", "Phải chọn đến chuyên mục tour con cuối cùng");
                //}

                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(model.Alias))
                    {
                        model.Alias = StringHelper.ConvertToAlias(model.Title);
                    }
                    try
                    {
                        DateTime?_start_deal;
                        int?     _time_deal;
                        if (model.Deal)
                        {
                            _start_deal = model.StartDeal;
                            _time_deal  = model.TimeDeal;
                        }
                        else
                        {
                            _start_deal = null;
                            _time_deal  = null;
                        }
                        var tour = new Tour
                        {
                            MenuID          = model.MenuID,
                            Title           = model.Title,
                            Alias           = model.Alias,
                            ToDes           = model.ToDes,
                            FromDes         = model.FromDes,
                            HotelService    = model.HotelService,
                            ThreeStar       = model.ThreeStar,
                            FourStar        = model.FourStar,
                            FiveStar        = model.FiveStar,
                            Deal            = model.Deal,
                            StartDeal       = _start_deal,
                            CheckCruise     = model.CheckCruise,
                            TimeDeal        = _time_deal,
                            Image           = model.Image,
                            Deposit         = model.Deposit,
                            Home            = model.Home,
                            Index           = 0,
                            Description     = model.Description,
                            MetaTitle       = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle,
                            MetaDescription =
                                string.IsNullOrEmpty(model.MetaDescription) ? model.Title : model.MetaDescription,
                            Status    = model.Status,
                            Price     = model.Price,
                            PriceSale = model.PriceSale,
                            Hot       = model.Hot,
                            Sale      = model.Sale,
                            Address   = model.Address,

                            //StartDeal = model.StartDeal,
                            TourOther = model.TourOther,
                        };

                        db.Tours.InsertOnSubmit(tour);
                        db.SubmitChanges();

                        //Thêm hình ảnh cho tour
                        if (model.EGalleryITems != null)
                        {
                            foreach (EGalleryITem itemGallery in model.EGalleryITems)
                            {
                                var gallery = new TourGallery
                                {
                                    LargeImage = itemGallery.Image,
                                    SmallImage = ReturnSmallImage.GetImageSmall(itemGallery.Image),
                                    TourID     = tour.ID,
                                    ImageLage  = itemGallery.Image,
                                };
                                db.TourGalleries.InsertOnSubmit(gallery);
                            }
                            db.SubmitChanges();
                        }
                        //Thêm tabtour
                        if (model.TabTours != null)
                        {
                            foreach (TabTour itemTabTour in model.TabTours)
                            {
                                var tabTour = new TabTour
                                {
                                    TourID   = tour.ID,
                                    TitleTab = itemTabTour.TitleTab,
                                    Content  = itemTabTour.Content,
                                    Price    = itemTabTour.Price,
                                };

                                db.TabTours.InsertOnSubmit(tabTour);
                            }
                            db.SubmitChanges();
                        }

                        TempData["Messages"] = "Successful";
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception exception)
                    {
                        LoadData();
                        ViewBag.Messages = "Error: " + exception.Message;
                        return(View(model));
                    }
                }
                LoadData();
                return(View(model));
            }
        }
示例#4
0
        public ActionResult BookTour(int id)
        {
            using (var db = new MyDbDataContext())
            {
                var  bookTour = new BookTour();
                Tour tour     = db.Tours.FirstOrDefault(a => a.ID == id);
                if (tour == null)
                {
                    var hotel = CommentController.DetailHotel(Request.Cookies["LanguageID"].Value);
                    ViewBag.Messages = "Error! Can not find the selected tous. For more information, please contact us by email: <a href='mailto:" + hotel.Email + "'>" + hotel.Email + "</a> or phone number: < href='tel:" + hotel.Tel + "'>" + hotel.Tel + "</a>";
                    return(View("Messages"));
                }
                int            caseOption = 0;
                string         name       = "";
                decimal        price      = 0;
                List <TabTour> tabtours   = new List <TabTour>();

                if (tour.HotelService == true)
                {
                    var option = Request.Params["option"];
                    int.TryParse(option, out caseOption);

                    switch (caseOption)
                    {
                    case 1:
                        name  = "3-Star Hotels - " + tour.Title;
                        price = (decimal)tour.ThreeStar;
                        break;

                    case 2:
                        name  = "4-Star Hotels - " + tour.Title;
                        price = (decimal)tour.FourStar;
                        break;

                    case 3:
                        name  = "5-Star Hotels - " + tour.Title;
                        price = (decimal)tour.FiveStar;
                        break;

                    default:
                        var hotel = CommentController.DetailHotel(Request.Cookies["LanguageID"].Value);
                        ViewBag.Messages = "Error! Can not find the selected tous. For more information, please contact us by email: <a href='mailto:" + hotel.Email + "'>" + hotel.Email + "</a> or phone number: < href='tel:" + hotel.Tel + "'>" + hotel.Tel + "</a>";
                        return(View("Messages"));
                    }
                    var tabtour = new TabTour
                    {
                        TourID   = 0,
                        TitleTab = name,
                        Price    = price
                    };
                    tabtours.Add(tabtour);
                }
                else
                {
                    var listTabtours = db.TabTours.Where(a => a.TourID == tour.ID && a.Price > 0).ToList();
                    if (listTabtours.Count > 0)
                    {
                        tabtours.AddRange(listTabtours);
                        if (listTabtours.Count > 1)
                        {
                            price = 0;
                        }
                        else
                        {
                            price = (decimal)listTabtours[0].Price;
                        }
                    }
                    else
                    {
                        var tabtour = new TabTour
                        {
                            TourID   = 0,
                            TitleTab = tour.Title,
                            Price    = tour.PriceSale
                        };
                        tabtours.Add(tabtour);
                    }
                }
                ViewBag.Tour         = tour;
                ViewBag.title        = tour.Title;
                ViewBag.tourID       = tour.ID;
                ViewBag.name         = name;
                ViewBag.price        = price;
                ViewBag.Option       = caseOption;
                bookTour.InfoBooking = tour.Title;
                bookTour.ID          = tour.ID;

                ViewBag.TabTours = tabtours;
                return(View("BookTour", bookTour));
            }
        }
示例#5
0
        public ActionResult Update(ETour model)
        {
            //Kiểm tra xem alias thuộc tour này đã tồn tại chưa
            var db = new MyDbDataContext();

            //Kiểm tra xem đã chọn đến chuyên mục con cuối cùng chưa
            //var check = db.Menus.Where(a => a.ParentID == model.ID).ToList();
            //if (db.Menus.Any(a => a.ParentID == model.ID))
            //{
            //    ModelState.AddModelError("MenuId", "Vui lòng chọn đến chuyên mục tour con cuối cùng");
            //}

            if (ModelState.IsValid)
            {
                try
                {
                    Tour tour = db.Tours.FirstOrDefault(b => b.ID == model.ID);
                    if (tour != null)
                    {
                        tour.MenuID          = model.MenuID;
                        tour.Title           = model.Title;
                        tour.Alias           = model.Alias;
                        tour.ToDes           = model.ToDes;
                        tour.FromDes         = model.FromDes;
                        tour.HotelService    = (bool)model.HotelService;
                        tour.ThreeStar       = (decimal)model.ThreeStar;
                        tour.FourStar        = (decimal)model.FourStar;
                        tour.FiveStar        = (decimal)model.FiveStar;
                        tour.Deal            = model.Deal;
                        tour.Image           = model.Image;
                        tour.Description     = model.Description;
                        tour.MetaTitle       = string.IsNullOrEmpty(model.MetaTitle) ? model.Title : model.MetaTitle;
                        tour.MetaDescription = string.IsNullOrEmpty(model.MetaDescription)
                            ? model.Title
                            : model.MetaDescription;
                        tour.Status    = model.Status;
                        tour.Home      = model.Home;
                        tour.Hot       = model.Hot;
                        tour.Sale      = model.Sale;
                        tour.Price     = model.Price;
                        tour.PriceSale = model.PriceSale;
                        tour.Deposit   = model.Deposit;
                        tour.Address   = model.Address;

                        if (model.Deal == true)
                        {
                            tour.StartDeal = model.StartDeal;
                            tour.TimeDeal  = model.TimeDeal;
                        }
                        else
                        {
                            tour.StartDeal = null;
                            tour.TimeDeal  = null;
                        }
                        //tour.StartDeal = model.StartDeal;
                        tour.TourOther = model.TourOther;
                        db.SubmitChanges();

                        //xóa gallery cho tour
                        db.TourGalleries.DeleteAllOnSubmit(db.TourGalleries.Where(a => a.TourID == tour.ID).ToList());
                        //Thêm hình ảnh cho tour
                        if (model.EGalleryITems != null)
                        {
                            foreach (EGalleryITem itemGallery in model.EGalleryITems)
                            {
                                var gallery = new TourGallery
                                {
                                    ImageLage  = itemGallery.Image,
                                    LargeImage = itemGallery.Image,
                                    SmallImage = ReturnSmallImage.GetImageSmall(itemGallery.Image),
                                    TourID     = tour.ID,
                                };
                                db.TourGalleries.InsertOnSubmit(gallery);
                            }
                            db.SubmitChanges();
                        }
                        //xóa danh sách tabtour
                        db.TabTours.DeleteAllOnSubmit(db.TabTours.Where(a => a.TourID == tour.ID).ToList());

                        //Thêm tabtour
                        if (model.TabTours != null)
                        {
                            foreach (TabTour itemTabTour in model.TabTours)
                            {
                                var tabTour = new TabTour
                                {
                                    TourID   = tour.ID,
                                    TitleTab = itemTabTour.TitleTab,
                                    Content  = itemTabTour.Content,
                                    Price    = itemTabTour.Price
                                };

                                db.TabTours.InsertOnSubmit(tabTour);
                            }
                            db.SubmitChanges();
                        }

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