コード例 #1
0
 /// <summary>
 /// Adds a new user
 /// </summary>
 /// <param name="user"></param>
 public void Post(Staff staff)
 {
     using (var db = new CorridorDBEntities())
     {
         db.Staffs.Add(new Staff {
             username = staff.username, firstname = staff.firstname,
             lastname = staff.lastname, email = staff.email,
             isAdmin  = staff.isAdmin, mobile = staff.mobile, roomNr = staff.roomNr
         });
         db.SaveChanges();
     }
 }
コード例 #2
0
        /// <summary>
        /// Returns a list of task for a specific staff with the roomNr = roomNr
        /// </summary>
        /// <param name="roomNr">Number of staffs room</param>
        /// <returns>a list of Tasks</returns>
        public List <Task> List(string roomNr)
        {
            List <Task> tasks = new List <Task>();

            using (var db = new CorridorDBEntities())
            {
                Staff staff = db.Staffs.Where(x => x.roomNr == roomNr).First();
                foreach (var sT in db.Staff_Task.Where(x => x.staffId == staff.staffId))
                {
                    tasks.Add(db.Tasks.Where(x => x.taskId == sT.taskId).First());
                }
            }

            return(tasks);
        }
コード例 #3
0
 /// <summary>
 /// returns a staff with staffId = staffId
 /// </summary>
 /// <param name="staffId"></param>
 /// <returns></returns>
 public Staff Get(int staffId)
 {
     try
     {
         Staff staff = new Staff();
         using (var db = new CorridorDBEntities())
         {
             staff = db.Staffs.Find(staffId);
         }
         return(staff);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #4
0
 /// <summary>
 /// returns a list of all corridors
 /// </summary>
 /// <returns>returns a list of all corridors</returns>
 public List <Corridor> List()
 {
     try
     {
         List <Corridor> lCorridor = new List <Corridor>();
         using (var db = new CorridorDBEntities())
         {
             lCorridor.AddRange(db.Corridors.ToList());
         }
         return(lCorridor);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #5
0
 /// <summary>
 /// Return user with username = username
 /// </summary>
 /// <param name="username"></param>
 /// <returns></returns>
 public Repository.Staff Get(string username)
 {
     try
     {
         Repository.Staff staff = new Staff();
         using (var db = new CorridorDBEntities())
         {
             staff = db.Staffs.Where(x => x.username == username).First();
         }
         return(staff);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #6
0
 /// <summary>
 /// returns a list of ALL users
 /// </summary>
 /// <returns>returns a list of ALL users</returns>
 public List <Repository.Staff> List()
 {
     try
     {
         List <Repository.Staff> LStaff = new List <Staff>();
         using (var db = new CorridorDBEntities())
         {
             LStaff.AddRange(db.Staffs.ToList());
         }
         return(LStaff);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #7
0
 /// <summary>
 /// updates tasks to and from time with Id = taskId
 /// </summary>
 /// <param name="updatedTask">task to update</param>
 public void updateTask(Task updatedTask)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Task task = db.Tasks.Where(x => x.taskId == updatedTask.taskId).First();
             task.fromTime = updatedTask.fromTime;
             task.toTime   = updatedTask.toTime;
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #8
0
 /// <summary>
 /// updates corridor name with it updatedcorridor.corridorId
 /// </summary>
 /// <param name="updatedCorridor"></param>
 public void Update(Corridor updatedCorridor)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Corridor corridor = db.Corridors.Find(updatedCorridor.corridorId);
             corridor.name      = updatedCorridor.name;
             corridor.eventInfo = updatedCorridor.eventInfo;
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #9
0
 /// <summary>
 /// Removes user with staffId= newStaffId from corridro with corridorIt username.corridorId
 /// </summary>
 /// <param name="newCorridorId"></param>
 /// <param name="newStaffId"></param>
 public void Delete(int newCorridorId, string username)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Staff          staff = db.Staffs.Include("Staff_Task").Where(x => x.username == username).First();
             Staff_Corridor sC    = db.Staff_Corridor.Find(staff.staffId);
             db.Staff_Corridor.Attach(sC);
             db.Staff_Corridor.Remove(sC);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #10
0
 /// <summary>
 /// adds a new corridor to database with name = corridorName
 /// </summary>
 /// <param name="corridorName"></param>
 public void Post(string corridorName)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Corridor corridor = new Corridor {
                 name = corridorName
             };
             db.Corridors.Add(corridor);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #11
0
        /// <summary>
        /// Deletes staff with username = username
        /// </summary>
        /// <param name="username"></param>
        public void Delete(string username)
        {
            try
            {
                using (var db = new CorridorDBEntities())
                {
                    Staff      staff      = db.Staffs.Where(x => x.username == username).First();
                    List <int> taskIdList = new List <int>();
                    foreach (Staff_Task sT in db.Staff_Task.Where(x => x.staffId == staff.staffId))
                    {
                        taskIdList.Add(Convert.ToInt32(sT.taskId));
                        db.Staff_Task.Attach(sT);
                        db.Staff_Task.Remove(sT);
                    }

                    db.SaveChanges();

                    foreach (int id in taskIdList)
                    {
                        if (db.Staff_Task.Where(x => x.staffId == id).Count() < 1)
                        {
                            Task task = db.Tasks.Where(x => x.taskId == id).First();
                            db.Tasks.Attach(task);
                            db.Tasks.Remove(task);
                        }
                    }

                    foreach (Staff_Corridor sC in db.Staff_Corridor.Where(x => x.staffId == staff.staffId))
                    {
                        db.Staff_Corridor.Attach(sC);
                        db.Staff_Corridor.Remove(sC);
                    }

                    db.Staffs.Attach(staff);
                    db.Staffs.Remove(staff);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #12
0
 /// <summary>
 /// Deletes task with Id == taskId
 /// </summary>
 /// <param name="taskId"></param>
 public void Delete(int taskId)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Staff_Task sT = db.Staff_Task.Where(x => x.taskId == taskId).First();
             db.Staff_Task.Attach(sT);
             db.Staff_Task.Remove(sT);
             Task task = db.Tasks.Where(x => x.taskId == taskId).First();
             db.Tasks.Attach(task);
             db.Tasks.Remove(task);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #13
0
 /// <summary>
 /// Returns user from corridor with id = corridorId
 /// </summary>
 /// <param name="corridorId"></param>
 /// <returns>Returns user from corridor with id = corridorId</returns>
 public List <Repository.Staff> List(int corridorId)
 {
     try
     {
         List <Repository.Staff> LStaff = new List <Staff>();
         using (var db = new CorridorDBEntities())
         {
             List <Staff_Corridor> LStaffCorridor = db.Staff_Corridor.Where(x => x.corridorId == corridorId).ToList();
             foreach (Staff_Corridor sc in LStaffCorridor)
             {
                 LStaff.Add(db.Staffs.Where(x => x.staffId == sc.staffId).First());
             }
         }
         return(LStaff);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #14
0
 /// <summary>
 /// Adds user with staffId = username.StaffId to corridor with corridorId = newCorridorId
 /// </summary>
 /// <param name="newCorridorId"></param>
 /// <param name="newStaffId"></param>
 public void Post(int newCorridorId, string username)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Staff          staff = db.Staffs.Where(x => x.username == username).First();
             Staff_Corridor sc    = new Staff_Corridor {
                 staffId = staff.staffId, corridorId = newCorridorId
             };
             Staff staffs = db.Staffs.Find(staff.staffId);
             staffs.Staff_Corridor.Add(sc);
             db.Staff_Corridor.Add(sc);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #15
0
 /// <summary>
 /// Adds a task
 /// </summary>
 /// <param name="task">task to add</param>
 public void Post(Task task, string username)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Staff staff = db.Staffs.Where(x => x.username == username).First();
             db.Tasks.Add(task);
             db.SaveChanges();
             Staff_Task sT = new Staff_Task {
                 staffId = staff.staffId, taskId = task.taskId
             };
             db.Staff_Task.Add(sT);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #16
0
 /// <summary>
 /// updates staff with username = updatedStaff.username
 /// </summary>
 /// <param name="updatedStaff"></param>
 public void Update(Staff updatedStaff)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Staff staff = db.Staffs.Where(x => x.username == updatedStaff.username).First();
             staff.firstname = updatedStaff.firstname;
             staff.lastname  = updatedStaff.lastname;
             staff.isAdmin   = Convert.ToBoolean(updatedStaff.isAdmin);
             staff.mobile    = updatedStaff.mobile;
             staff.roomNr    = updatedStaff.roomNr;
             staff.email     = updatedStaff.email;
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #17
0
 /// <summary>
 /// removes corridor with corridorId = corridorId
 /// </summary>
 /// <param name="corridorId"></param>
 public void Delete(int corridorId)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             foreach (var sC in db.Staff_Corridor.Where(x => x.corridorId == corridorId))
             {
                 db.Staff_Corridor.Attach(sC);
                 db.Staff_Corridor.Remove(sC);
             }
             Corridor corridor = db.Corridors.Where(x => x.corridorId == corridorId).First();
             db.Corridors.Attach(corridor);
             db.Corridors.Remove(corridor);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #18
0
 /// <summary>
 /// Adds a list of tasks
 /// </summary>
 /// <param name="tasks">Tasks to add</param>
 public void Post(List <Task> tasks, string username)
 {
     try
     {
         using (var db = new CorridorDBEntities())
         {
             Staff      staff  = db.Staffs.Where(x => x.username == username).First();
             List <int> idlist = new List <int>();
             foreach (Task t in tasks)
             {
                 db.Tasks.Add(t);
                 db.SaveChanges();
                 db.Staff_Task.Add(new Staff_Task {
                     staffId = staff.staffId, taskId = t.taskId
                 });
             }
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }