public ActionResult GetOfficerDetails(int id)
        {
            officer officer = (from item in db.officers
                               where item.officerID == id
                               select item).FirstOrDefault();


            officerStayIn room = (from item in db.officerStayIns
                                  where item.officerid == id
                                  select item).FirstOrDefault();

            OfficerWorkA work = (from item in db.OfficerWorkAs
                                 where item.officerid == id
                                 select item).FirstOrDefault();

            OfficerDetails officerDetails = new OfficerDetails();

            officerDetails.officer = officer;
            if (room != null)
            {
                officerDetails.room = room.officerRoom;
            }
            if (work != null)
            {
                officerDetails.job = work.Job;
            }

            return(View(officerDetails));
        }
        //assign aroom randomly for a specific officer
        private void AssignARoom(officer officer)
        {
            var maxRoomID = (from item in db.officerRooms
                             where item.isActive == true
                             orderby item.officerRoomID descending
                             select item.officerRoomID).FirstOrDefault();

            var minRoomID = (from item in db.officerRooms
                             where item.isActive == true
                             orderby item.officerRoomID ascending
                             select item.officerRoomID).FirstOrDefault();

            Random rnd            = new Random();
            int    selectedRoomID = rnd.Next(minRoomID, maxRoomID);


            var selectedRoom = (from item in db.officerRooms
                                where item.officerRoomID == selectedRoomID
                                select item).FirstOrDefault();

            if (selectedRoom != null)
            {
                officerStayIn relation = new officerStayIn();
                relation.officer       = officer;
                relation.officerid     = officer.officerID;
                relation.officerRoom   = selectedRoom;
                relation.officerRoomid = selectedRoom.officerRoomID;
                relation.since         = DateTime.Now;

                db.Entry(relation).State = EntityState.Added;
                db.SaveChanges();

                selectedRoom.isActive        = false;
                db.Entry(selectedRoom).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        // GET: OfficerRooms/Details/5
        public ActionResult Details(int id)
        {
            var relation = (from item in db.officerStayIns
                            where item.officerRoomid == id
                            select item).FirstOrDefault();

            if (relation != null)
            {
                return(View(relation));
            }
            else
            {
                var officerRoom = (from item in db.officerRooms
                                   where item.officerRoomID == id
                                   select item).FirstOrDefault();

                officerStayIn tempRelation = new officerStayIn();

                tempRelation.officerRoom   = officerRoom;
                tempRelation.officerRoomid = officerRoom.officerRoomID;

                return(View(tempRelation));
            }
        }