Esempio n. 1
0
        public bool AddImagesToRoom()
        {
            if (IsUserLoggedIn())
            {
                bool isSavedSuccessfully = true;
                try
                {

                    string Name = "";
                    RoomData rd = null;
                    if (Session["RoomsData"] != null)
                    {
                        rd = Session["RoomsData"] as RoomData;
                    }
                    else
                    {
                        return false;
                    }
                    foreach (string fileName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[fileName];
                        Name = file.FileName;

                        if (file != null && file.ContentLength > 0)
                        {
                            string serverMapPath = Server.MapPath(@"/");
                            var originalDirectory = new DirectoryInfo(string.Format("{0}Images", serverMapPath));

                            string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "");
                            string fileName1 = "image_" + DateTime.Now.ToString("dd_MM_hh_mm_ss") + Name;
                            bool doessExists = System.IO.Directory.Exists(pathString);
                            if (!doessExists)
                                System.IO.Directory.CreateDirectory(pathString);
                            var path = string.Format("{0}\\{1}", pathString, fileName1);
                            file.SaveAs(path);
                            string PathForDb = path.Remove(0, serverMapPath.Length);
                            PathForDb = PathForDb.Replace(@"\", "/");
                            RoomPhoto rf = new RoomPhoto();
                            rf.Path = PathForDb;
                            rd.RoomPhotos.Add(rf);

                        }

                    }

                }
                catch (Exception ex)
                {
                    isSavedSuccessfully = false;
                }
                return isSavedSuccessfully;
            }
            else
            {
                return false;
            }
        }
Esempio n. 2
0
        public ActionResult DeleteRoom(int roomId, int sequencenumber)
        {
            if (IsUserLoggedIn())
            {
                Models.MoveToLondon mtl = new Models.MoveToLondon();
                List<Room> rooms = mtl.Rooms.Where(o => o.RoomSequence == sequencenumber).ToList();
                List<int> roomids = new List<int>();
                List<int> photoids = new List<int>();
                List<string> photopaths = new List<string>();
                foreach (Room room in rooms)
                {
                    if (!roomids.Contains(room.ID))
                        roomids.Add(room.ID);
                    List<RoomsPhotosBridge> bridges = room.RoomsPhotosBridges.ToList();

                    foreach (RoomsPhotosBridge bridge in bridges)
                    {
                        if (!photoids.Contains(bridge.PhotoId))
                        {
                            photoids.Add(bridge.PhotoId);
                            photopaths.Add(bridge.RoomPhoto.Path);
                        }
                        mtl.Entry(bridge).State = System.Data.Entity.EntityState.Deleted;
                    }
                }

                mtl.SaveChanges();
                mtl = null;
                mtl = new Models.MoveToLondon();
                foreach (int id in roomids)
                {
                    Room r = new Room();
                    r.ID = id;
                    mtl.Entry(r).State = System.Data.Entity.EntityState.Deleted;
                }

                foreach (int id in photoids)
                {
                    RoomPhoto rf = new RoomPhoto();
                    rf.ID = id;
                    mtl.Entry(rf).State = System.Data.Entity.EntityState.Deleted;
                }
                //string serverpath = Server.MapPath(@"/");
                //foreach (string path in photopaths)
                //{

                //}
                mtl.SaveChanges();
                return RedirectToAction("roomslist");
            }
            else
            {
                return RedirectToAction("index");
            }
        }
Esempio n. 3
0
        private List<Room> GetListOfRooms()
        {
            Models.MoveToLondon mtl = new Models.MoveToLondon();

            List<Room> rooms = new List<Models.Room>();
            if (Convert.ToBoolean(Session["IsEnglishVersion"]) == true)
            {
                rooms = mtl.Rooms.Where(o => !o.IsFrench).ToList();
            }
            else
            {
                rooms = mtl.Rooms.Where(o => o.IsFrench).ToList();
            }

            return rooms;

            string serverMapPath = Server.MapPath(@"/");
            string filepath = Convert.ToBoolean(Session["IsEnglishVersion"]) ? serverMapPath + ConfigurationManager.AppSettings["EnglishRoomDataFilePath"].ToString()
                : serverMapPath + ConfigurationManager.AppSettings["FrenchRoomDataFilePath"].ToString();
            string line = string.Empty;
            List<Room> roomsList = new List<Room>();
            int roomsCounter = -1;
            bool isDescriptionStarted = false;
            string description = string.Empty;
            bool isPathsStarted = false;

            using (StreamReader sr = new StreamReader(filepath))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.StartsWith("***"))
                    {
                        Room room = new Room();
                        roomsList.Add(room);
                        roomsCounter++;
                        isPathsStarted = false;
                        continue;
                    }
                    if (line.Trim().ToLower().StartsWith("title:"))
                    {
                        roomsList[roomsCounter].Title = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        continue;
                    }
                    if (line.Trim().ToLower().StartsWith("address:"))
                    {
                        roomsList[roomsCounter].Address = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        continue;
                    }
                    if (line.Trim().ToLower().StartsWith("rentpermonth:"))
                    {
                        int rent = 0;
                        int.TryParse(line.Trim().Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1], out rent);
                        roomsList[roomsCounter].RentPerMonth = rent;
                        continue;
                    }
                    if (line.Trim().ToLower().StartsWith("description:"))
                    {

                        isDescriptionStarted = true;
                        description += line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        continue;
                    }
                    if (line.Trim().ToLower().StartsWith("photospaths:"))
                    {
                        isDescriptionStarted = false;
                        roomsList[roomsCounter].Description = description;
                        description = string.Empty;
                        isPathsStarted = true;
                        continue;
                    }
                    if (isDescriptionStarted)
                    {

                        description += "\n" + line;
                    }
                    if (isPathsStarted)
                    {
                        RoomPhoto rf = new RoomPhoto();
                        rf.Path = line.Trim();
                        //if (roomsList[roomsCounter].ListRoomPhoto == null)
                        //    roomsList[roomsCounter].ListRoomPhoto = new List<RoomPhoto>();
                        //roomsList[roomsCounter].ListRoomPhoto.Add(rf);
                    }

                }
            }

            return roomsList;
        }