/// <summary> /// Ajoute une nouvelle personne à un groupe /// </summary> /// <param name="adminID">Le ID de la personne qui tente d'ajouter une personne au group</param> /// <param name="personId">Le ID de la person qui doit être ajouté</param> /// <param name="groupId">Le ID du group de lequl ajouter la personne</param> public void AddPersonToGroup(object adminID, object personId, object groupId) { if (personId == null) { throw new ServiceException("Le ID de la personne est null"); } if (groupId == null) { throw new ServiceException("Le ID du groupe est null"); } if (adminID == null) { throw new ServiceException("Le ID de l'administrateur est null"); } try { using (var context = new pigeonsEntities1()) { // Validating the group group theGroup = groupDAO.GetByID(context, groupId); if (theGroup == null) { throw new ServiceException("Ce groupe n'existe pas"); } if (!theGroup.Is_active) { throw new ServiceException("Ce groupe n'est pas actif"); } List <following> followingList = followingDAO.GetBy(context, following.COLUMN_GROUP_ID, groupId).ToList(); foreach (following follow in followingList) { // If the user is already following that group if (follow.Person_Id == (int)personId && follow.Is_active) { throw new ServiceException("Cette personne suis déjà ce groupe"); } // He was following the group but was deactivated - Reactivating the person else if (follow.Person_Id == (int)personId && !follow.Is_active) { follow.Is_active = true; followingDAO.Update(context, follow); context.SaveChanges(); return; } // The user adding is not admin of this group if (follow.Person_Id == (int)adminID && !follow.Is_admin) { throw new ServiceException("La personne qui tente d'ajouter une autre personne n'est pas l'administrateur du groupe"); } } // Everyting is ok, adding the following following newFollowing = new following(); newFollowing.Person_Id = (int)personId; newFollowing.Group_id = (int)groupId; newFollowing.Is_admin = false; newFollowing.Is_active = true; newFollowing.Last_checkin = DateTime.Now; followingDAO.Insert(context, newFollowing); context.SaveChanges(); } } catch (DAOException daoException) { throw new ServiceException(daoException.Message); } }