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"); } }
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; }