/// <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 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; } }