Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }