Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public static ParentSimpleViewDTO ParentToParentSimpleViewDTO(Parent user)
        {
            ParentSimpleViewDTO retVal = new ParentSimpleViewDTO();

            retVal.Id        = user.Id;
            retVal.FirstName = user.FirstName;
            retVal.LastName  = user.LastName;
            retVal.UserName  = user.UserName;
            retVal.Email     = user.Email;

            if (user.Students.Count < 0)
            {
                retVal.Students = null;
            }
            else
            {
                retVal.Students = user.Students.Select(child =>
                {
                    UserSimpleViewDTO dto = UserToUserSimpleViewDTO(child);
                    return(dto);
                }).ToList();
            }

            logger.Info("Convetring Parent to ParentSimpleViewDTO.");
            return(retVal);
        }
Ejemplo n.º 3
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);
        }
        public IHttpActionResult DeleteStudent(string id)
        {
            UserSimpleViewDTO retVal = service.DeleteStudent(id);

            if (retVal == null)
            {
                logger.Warn($"Student with id {id} not found.");
                return(BadRequest());
            }

            logger.Info($"Deleting student with id {id}");
            return(Ok(retVal));
        }
        public IHttpActionResult GetTeacherById(string id)
        {
            UserSimpleViewDTO retVal = service.GetTeacherById(id);

            if (retVal == null)
            {
                logger.Warn("Teacher with id {0} not found", id);
                return(NotFound());
            }

            logger.Info($"Getting teacher with id {id}");
            return(Ok(retVal));
        }
        public IHttpActionResult GetAdminById(string id)
        {
            UserSimpleViewDTO retVal = service.GetAdminById(id);

            if (retVal == null)
            {
                logger.Warn("Admin with id {0} not found", id);
                return(NotFound());
            }

            logger.Info("Getting admin with id {0}", id);
            return(Ok(retVal));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
        public IHttpActionResult GetMySelfAdmin()
        {
            string userId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;

            UserSimpleViewDTO retVal = service.GetAdminById(userId);

            if (retVal == null)
            {
                logger.Info("Not found admin with id {0}", userId);
                return(NotFound());
            }

            logger.Info("Returning admin with id {0}", userId);
            return(Ok(retVal));
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }