public UserSimpleViewDTO DeleteParent(string id) { Parent parent = db.ParentsRepository.Get(user => user.Id == id).FirstOrDefault(); IEnumerable <Student> students = db.StudentsRepository.Get(s => s.Parent.Id == parent.Id); if (parent == null) { logger.Warn("Parent with id {0} not found.", id); return(null); } foreach (var item in students) { logger.Info("Removing child with id {0} from parents' children list. Parent id {1}", item.Id, id); item.Parent = null; } db.ParentsRepository.Delete(parent); db.Save(); logger.Info("Parent with id {0} deleted.", id); UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(parent); return(retVal); }
public UserSimpleViewDTO DeleteAdmin(string id) { Admin admin = db.AdminsRepository.Get(user => user.Id == id).FirstOrDefault(); int adminCount = db.AdminsRepository.Get().Count(); if (admin == null) { logger.Warn("Admin with id {0} not found."); return(null); } if (adminCount < 2) { logger.Warn("Less than 2 admins present in the system. Can't delete the last one!"); return(null); } db.AdminsRepository.Delete(admin); db.Save(); logger.Info("Deleting admin with id {0}", id); UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(admin); return(retVal); }
public IEnumerable <UserSimpleViewDTO> GetAllAdmins() { IEnumerable <ApplicationUser> users = db.AdminsRepository.Get(); logger.Info("Getting all admins."); IEnumerable <UserSimpleViewDTO> retVal = users.Select(x => UserToUserDTOConverters.UserToUserSimpleViewDTO(x)); return(retVal); }
public UserSimpleViewDTO GetTeacherById(string id) { Teacher teacher = db.TeachersRepository.Get(user => user.Id == id).FirstOrDefault(); if (teacher == null) { logger.Warn("No such teacher. {0}", id); return(null); } logger.Info("Getting teacher with id {0}", id); UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(teacher); return(retVal); }
public UserSimpleViewDTO GetAdminById(string id) { Admin admin = db.AdminsRepository.Get(user => user.Id == id).FirstOrDefault(); if (admin == null) { logger.Warn("No such admin. {0}", id); return(null); } logger.Info("Getting admin with id {0}", id); UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(admin); return(retVal); }
public UserSimpleViewDTO DeleteStudent(string id) { Student student = db.StudentsRepository.Get(user => user.Id == id).FirstOrDefault(); if (student == null) { logger.Warn("Student with id {0} not found.", id); return(null); } db.StudentsRepository.Delete(student); db.Save(); logger.Info("Student with id {0} deleted.", id); UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(student); return(retVal); }
public UserSimpleViewDTO DeleteTeacher(string id) { Teacher teacher = db.TeachersRepository.Get(user => user.Id == id).FirstOrDefault(); if (teacher == null) { logger.Warn("Teacher with id {0} not found.", id); return(null); } db.TeachersRepository.Delete(teacher); db.Save(); logger.Info("Teacher with id {0} deleted.", id); UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(teacher); return(retVal); }