Пример #1
0
 public RoomController()
 {
     if (db == null)
     {
         db = new WGHotelBaseEntities();
     }
 }
Пример #2
0
        public void Edit()
        {
            var db    = new WGHotelBaseEntities();
            var Model = db.Report.Find(ID);

            Model.Modified = Modified;
            Model.Modify   = Modify;
            //var Model = new Report();
            //Model.Created = Created;
            //Model.Creator = Creator;
            var country_id = int.Parse(Country);
            var country    = db.Country.Find(country_id);

            Model.CountryID   = country.ID;
            Model.Country     = country.Name;
            Model.CheckInDate = CheckInDate;
            Model.HotelID     = HotelID;
            Model.NumOfPeople = NumOfPeople;
            Model.Price       = Price;
            Model.RoomID      = RoomID;
            Model.Room        = Room;
            Model.Food        = Food;
            Model.FoodCost    = FoodCost;
            Model.Other       = Other;
            Model.OtherCost   = OtherCost;
            Model.UserType    = UserType;
            var ReportRooms   = new List <ReportRooms>();
            var ReportRoomsOf = new List <ReportRooms>();

            //ar RemoveModel =
            if (!string.IsNullOrEmpty(Room))
            {
                var RoomString = Room;
                var RoomSpilt  = RoomString.Split(',');
                foreach (var ro in RoomSpilt)
                {
                    var room = ro.Split('^');
                    var id   = int.Parse(room[0]);
                    var amt  = int.Parse(room[1]);
                    var name = room[2];
                    ReportRoomsOf.Add(new ReportRooms {
                        ID = ID, RoomID = id, Amount = amt, RoomName = name
                    });
                    // if (!db.ReportRooms.Any(o => o.ReportID == ID && o.RoomID == id && o.Amount == amt))
                    //{
                    ReportRooms.Add(new ReportRooms {
                        RoomID = id, Amount = amt, RoomName = name
                    });
                    //}
                }

                var rrIDs = ReportRoomsOf.Select(o => o.RoomID).ToList();
                //var remove = db.ReportRooms.Where(o => !rrIDs.Contains(o.RoomID)).ToList();
                var removemodel = db.ReportRooms.Where(o => o.ReportID == ID).ToList();
                db.ReportRooms.RemoveRange(removemodel);
                Model.ReportRooms = ReportRooms;
            }
            //db.Report.Add(Model);
            db.SaveChanges();
        }
Пример #3
0
        public object HotelImageDelete(ImageViewModel data)
        {
            if (HttpContext.Current.Session[data.SessionKey] != null)
            {
                var images = (List <ImageViewModel>)HttpContext.Current.Session[data.SessionKey];
                var img    = new ImageViewModel();
                if (images.Count > 0)
                {
                    img = images.Where(o => o.Name == data.Name).FirstOrDefault();
                    if (img != null)
                    {
                        images.Remove(images.Where(o => o.Name == img.Name).FirstOrDefault());
                        new ImageDAO().Delete(img.Name);

                        using (var db = new WGHotelBaseEntities())
                        {
                            var dbimg = db.ImageStore.Where(o => o.Name == img.Name).FirstOrDefault();
                            if (dbimg != null)
                            {
                                db.ImageStore.Remove(dbimg);
                                db.SaveChanges();
                            }
                        }
                    }
                }



                HttpContext.Current.Session[data.SessionKey] = images;
            }

            return(Json(new { success = true }));
        }
Пример #4
0
        public void SaveImageStore(int ZHID, int USID)
        {
            var Session = HttpContext.Current.Session;

            if (Session[ImgKey] != null)
            {
                var Basedb   = new WGHotelBaseEntities();
                var Now      = DateTime.Now;
                var images   = (List <ImageViewModel>)Session[ImgKey];
                var dbimages = Basedb.ImageStore.Where(o => o.ReferIdZH == ZHID && o.ReferIdUS == USID).ToList();
                foreach (var img in images)
                {
                    if (!dbimages.Any(o => o.Name == img.Name))
                    {
                        var fileName = Guid.NewGuid().GetHashCode().ToString("x");
                        //var file = string.Format("/UserFolder/{0}{1}",fileName, img.Extension);
                        //var path = HttpContext.Current.Server.MapPath(file);
                        //File.WriteAllBytes(path, img.Image);
                        Basedb.ImageStore.Add(new ImageStore
                        {
                            // Path = file,
                            Created   = Now,
                            Extension = img.Extension,
                            Deleted   = false,
                            ReferIdUS = USID,
                            ReferIdZH = ZHID,
                            Type      = "Room",
                            Name      = fileName,
                            Image     = img.Image
                        });
                    }
                }
                Basedb.SaveChanges();
            }
        }
Пример #5
0
 private void SetDefault()
 {
     using (var db = new WGHotelBaseEntities())
     {
         var data = db.SysSetting.Where(o => o.Code.Equals("RoomCanEditDate")).ToList();
         Begin = data.Where(o => o.Name == "Begin").FirstOrDefault().Value;
         End   = data.Where(o => o.Name == "End").FirstOrDefault().Value;
     }
 }
Пример #6
0
        // GET: Base
        public BaseController()
            : base()
        {
            _dbzh   = new WGHotelZHEntities();
            _dbus   = new WGHotelUSEntities();
            _basedb = new WGHotelBaseEntities();

            //var RoomEditDate = new PRDate();
            //var RoomEditBeginDate = DateTime.Parse(RoomEditDate.Begin);
            //var RoomEditEndDate = DateTime.Parse(RoomEditDate.End);
            //ViewBag.GameSite = new GameSiteModel().SelectList();
        }
Пример #7
0
        public void Edit()
        {
            using (var db = new WGHotelBaseEntities())
            {
                var data      = db.SysSetting.Where(o => o.Code.Equals("RoomCanEditDate")).ToList();
                var BeginId   = data.Where(o => o.Name == "Begin").FirstOrDefault().ID;
                var EndId     = data.Where(o => o.Name == "End").FirstOrDefault().ID;
                var BeginDate = db.SysSetting.Where(o => o.ID == BeginId).FirstOrDefault();
                BeginDate.Value = Begin;

                var EndDate = db.SysSetting.Where(o => o.ID == EndId).FirstOrDefault();
                EndDate.Value = End;
                db.SaveChanges();
            }
        }
Пример #8
0
        public void Create()
        {
            var db    = new WGHotelBaseEntities();
            var Model = new Report();

            Model.Created = Created;
            Model.Creator = Creator;
            //Model.CountryID = CountryID;
            var country_id = int.Parse(Country);
            var country    = db.Country.Find(country_id);

            Model.CountryID   = country.ID;
            Model.Country     = country.Name;
            Model.CheckInDate = CheckInDate;
            Model.HotelID     = HotelID;
            Model.NumOfPeople = NumOfPeople;
            Model.Price       = Price;
            Model.RoomID      = RoomID;
            Model.Modified    = Modified;
            Model.Modify      = Modify;
            Model.Room        = Room;
            Model.Food        = Food;
            Model.FoodCost    = FoodCost;
            Model.Other       = Other;
            Model.OtherCost   = OtherCost;
            Model.UserType    = UserType;

            var ReportRooms = new List <ReportRooms>();

            var RoomString = Room;
            var RoomSpilt  = RoomString.Split(',');

            foreach (var ro in RoomSpilt)
            {
                var room = ro.Split('^');
                var id   = int.Parse(room[0]);
                var amt  = int.Parse(room[1]);
                var name = room[2];
                ReportRooms.Add(new ReportRooms {
                    RoomID = id, Amount = amt, RoomName = name
                });
            }

            Model.ReportRooms = ReportRooms;

            db.Report.Add(Model);
            db.SaveChanges();
        }
Пример #9
0
        public ActionResult Edit(string key)
        {
            var models = (List <ImageViewModel>)Session[key];

            using (WGHotelBaseEntities db = new WGHotelBaseEntities())
            {
                var Now = DateTime.Now;
                foreach (var img in models)
                {
                    var Folder = "/images/banners";
                    if (!Directory.Exists(Server.MapPath(Folder)))
                    {
                        Directory.CreateDirectory(Server.MapPath(Folder));
                    }

                    var FileName = Guid.NewGuid().GetHashCode().ToString("x").ToUpper();

                    var Path = string.Format("{0}/{1}{2}", Folder, FileName, img.Extension);

                    MemoryStream ms          = new MemoryStream(img.Image);
                    Image        returnImage = Image.FromStream(ms);
                    returnImage.Save(Server.MapPath(Path));

                    db.Banner.Add(new Banner
                    {
                        Image     = img.Image,
                        Extension = img.Extension,
                        Enabled   = true,
                        Path      = Path,
                        Name      = img.Name,
                    });
                }
                db.SaveChanges();
            }
            try
            {
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #10
0
        public void Create()
        {
            var ZHdb    = new WGHotelZHEntities();
            var zhHotel = new Hotel();

            zhHotel.Name       = Namezh;
            zhHotel.Address    = Addresszh;
            zhHotel.Area       = Area;
            zhHotel.City       = City;
            zhHotel.Facilities = Facilies;
            zhHotel.Features   = Featurezh;
            zhHotel.Enabled    = true;
            zhHotel.LinkUrl    = LinkUrl;
            zhHotel.Game       = Game;
            zhHotel.Tel        = Tel;
            zhHotel.UserId     = UserId;


            ZHdb.Hotel.Add(zhHotel);
            ZHdb.SaveChanges();
            var ReferIdZH = zhHotel.ID;
            var ReferIdUS = 0;

            try
            {
                var USdb    = new WGHotelUSEntities();
                var HotelUs = new Hotel
                {
                    Name       = Nameus,
                    Address    = Addressus,
                    Area       = Area,
                    City       = City,
                    Facilities = Facilies,
                    Features   = Featureus,
                    Enabled    = true,
                    LinkUrl    = LinkUrl,
                    Game       = Game,
                    UserId     = UserId,
                    Tel        = Tel,
                    ParentId   = zhHotel.ID
                };
                USdb.Hotel.Add(HotelUs);

                USdb.SaveChanges();
                ReferIdUS = HotelUs.ID;

                var Session = HttpContext.Current.Session;

                if (Session[ImgKey] != null)
                {
                    var Basedb = new WGHotelBaseEntities();
                    var Now    = DateTime.Now;
                    var images = (List <ImageViewModel>)Session[ImgKey];
                    foreach (var img in images)
                    {
                        var fileName = Guid.NewGuid().GetHashCode().ToString("x");
                        Basedb.ImageStore.Add(new ImageStore
                        {
                            Created   = Now,
                            Extension = img.Extension,
                            Deleted   = false,
                            ReferIdUS = ReferIdUS,
                            ReferIdZH = ReferIdZH,
                            Type      = "Hotel",
                            Name      = fileName,
                            Image     = img.Image
                        });
                    }
                    Basedb.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                var ZH = ZHdb.Hotel.Find(zhHotel.ID);
                if (ZH != null)
                {
                    ZHdb.Hotel.Remove(ZH);
                    ZHdb.SaveChanges();
                }
            }
        }
Пример #11
0
        public void Edit()
        {
            var ZHdb    = new WGHotelZHEntities();
            var zhHotel = ZHdb.Hotel.Find(ID);

            zhHotel.Name       = Namezh;
            zhHotel.Address    = Addresszh;
            zhHotel.Area       = Area;
            zhHotel.City       = City;
            zhHotel.Facilities = Facilies;
            zhHotel.Features   = Featurezh;
            zhHotel.Enabled    = true;
            zhHotel.LinkUrl    = LinkUrl;
            zhHotel.Game       = Game;
            zhHotel.Tel        = Tel;
            //zhHotel.UserId = zhHotel.UserId;


            //ZHdb.Hotel.Add(zhHotel);

            var ReferIdZH = zhHotel.ID;

            try
            {
                var USdb    = new WGHotelUSEntities();
                var HotelUs = USdb.Hotel.Where(o => o.ParentId == ReferIdZH).FirstOrDefault();

                HotelUs.Name       = Nameus;
                HotelUs.Address    = Addressus;
                HotelUs.Area       = Area;
                HotelUs.City       = City;
                HotelUs.Facilities = Facilies;
                HotelUs.Features   = Featureus;
                HotelUs.Enabled    = true;
                HotelUs.LinkUrl    = LinkUrl;
                HotelUs.Game       = Game;
                //HotelUs.UserId = UserId;
                HotelUs.Tel      = Tel;
                HotelUs.ParentId = zhHotel.ID;

                // USdb.Hotel.Add(HotelUs);

                USdb.SaveChanges();

                ZHdb.SaveChanges();

                var ReferIdUS = HotelUs.ID;
                var Session   = HttpContext.Current.Session;

                if (Session[ImgKey] != null)
                {
                    var Basedb   = new WGHotelBaseEntities();
                    var Now      = DateTime.Now;
                    var images   = (List <ImageViewModel>)Session[ImgKey];
                    var dbImg    = Basedb.ImageStore.Where(o => o.ReferIdZH == zhHotel.ID);
                    var ImgNames = dbImg.Select(o => o.Name).ToList();
                    images = images.Where(o => !ImgNames.Contains(o.Name)).ToList();
                    foreach (var img in images)
                    {
                        var fileName = Guid.NewGuid().GetHashCode().ToString("x");
                        Basedb.ImageStore.Add(new ImageStore
                        {
                            Created   = Now,
                            Extension = img.Extension,
                            Deleted   = false,
                            ReferIdUS = ReferIdUS,
                            ReferIdZH = ReferIdZH,
                            Type      = "Hotel",
                            Name      = fileName,
                            Image     = img.Image
                        });
                    }
                    Basedb.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }