Пример #1
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"));
            }
        }
Пример #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");
            }
        }
Пример #3
0
        public ActionResult SaveAd()
        {
            if (IsUserLoggedIn())
            {
                try
                {
                    RoomData rd = Session["RoomsData"] as RoomData;
                    if (rd == null)
                    {
                        return RedirectToAction("index", "admin");
                    }

                    Models.MoveToLondon mtl = new Models.MoveToLondon();

                    for (int i = 0; i < rd.Rooms.Count; i++)
                    {
                        for (int j = 0; j < rd.RoomPhotos.Count; j++)
                        {
                            RoomsPhotosBridge rpb = new RoomsPhotosBridge();
                            rpb.Room = rd.Rooms[i];
                            rpb.RoomPhoto = rd.RoomPhotos[j];

                            mtl.Set<RoomsPhotosBridge>().Add(rpb);

                            //rd.Rooms[i].RoomsPhotosBridges.Clear();
                            //rd.RoomPhotos[j].RoomsPhotosBridges.Clear();

                            rd.Rooms[i].RoomsPhotosBridges.Add(rpb);
                            rd.RoomPhotos[j].RoomsPhotosBridges.Add(rpb);
                        }
                    }
                    Room r = mtl.Rooms.ToList().Last();
                    if (r != null)
                    {
                        rd.Rooms[0].RoomSequence = r.ID + 1;
                        rd.Rooms[1].RoomSequence = r.ID + 1;
                    }
                    else
                    {
                        rd.Rooms[0].RoomSequence = 0;
                        rd.Rooms[1].RoomSequence = 0;
                    }

                    foreach (Room room in rd.Rooms)
                    {
                        mtl.Set<Room>().Add(room);
                    }
                    foreach (RoomPhoto photo in rd.RoomPhotos)
                    {
                        mtl.Set<RoomPhoto>().Add(photo);
                    }
                    mtl.SaveChanges();
                }
                catch (Exception ex)
                {

                    throw;
                }

                return RedirectToAction("roomslist");
            }
            else
            {
                return RedirectToAction("index");
            }
        }
Пример #4
0
        public ActionResult SaveAd()
        {
            if (IsUserLoggedIn())
            {
                try
                {
                    RoomData rd = Session["RoomsData"] as RoomData;
                    if (rd == null)
                    {
                        return(RedirectToAction("index", "admin"));
                    }

                    Models.MoveToLondon mtl = new Models.MoveToLondon();

                    for (int i = 0; i < rd.Rooms.Count; i++)
                    {
                        for (int j = 0; j < rd.RoomPhotos.Count; j++)
                        {
                            RoomsPhotosBridge rpb = new RoomsPhotosBridge();
                            rpb.Room      = rd.Rooms[i];
                            rpb.RoomPhoto = rd.RoomPhotos[j];

                            mtl.Set <RoomsPhotosBridge>().Add(rpb);

                            //rd.Rooms[i].RoomsPhotosBridges.Clear();
                            //rd.RoomPhotos[j].RoomsPhotosBridges.Clear();

                            rd.Rooms[i].RoomsPhotosBridges.Add(rpb);
                            rd.RoomPhotos[j].RoomsPhotosBridges.Add(rpb);
                        }
                    }
                    Room r = mtl.Rooms.ToList().Last();
                    if (r != null)
                    {
                        rd.Rooms[0].RoomSequence = r.ID + 1;
                        rd.Rooms[1].RoomSequence = r.ID + 1;
                    }
                    else
                    {
                        rd.Rooms[0].RoomSequence = 0;
                        rd.Rooms[1].RoomSequence = 0;
                    }


                    foreach (Room room in rd.Rooms)
                    {
                        mtl.Set <Room>().Add(room);
                    }
                    foreach (RoomPhoto photo in rd.RoomPhotos)
                    {
                        mtl.Set <RoomPhoto>().Add(photo);
                    }
                    mtl.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw;
                }

                return(RedirectToAction("roomslist"));
            }
            else
            {
                return(RedirectToAction("index"));
            }
        }