Exemplo n.º 1
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;
            }
        }
 /// <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;
     }
 }
Exemplo n.º 3
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();
     }
 }
 /// <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;
     }
 }
 /// <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;
     }
 }
 /// <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;
     }
 }
 /// <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;
     }
 }
 /// <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;
     }
 }
 /// <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;
     }
 }
Exemplo n.º 10
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;
     }
 }
 /// <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;
     }
 }
 /// <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;
     }
 }