Exemplo n.º 1
0
        public IActionResult GetUsersByRoleId(int roleId)
        {
            AdminDataAccess        adm      = new AdminDataAccess();
            List <UserOutputModel> allUsers = new List <UserOutputModel>();
            UserMapper             mapper   = new UserMapper();
            var role = adm.GetRoleByRoleId(roleId);

            if (role == null)
            {
                return(BadRequest("Указанной роли не существует"));
            }
            foreach (UserDTO user in adm.GetUsersByRoleId(roleId))
            {
                allUsers.Add(mapper.ConvertUserDTOToUserOutputModel(user));
            }
            return(Ok(allUsers));
        }
Exemplo n.º 2
0
        public IActionResult GetAllGroups()
        {
            AdminDataAccess         adm = new AdminDataAccess();
            List <GroupOutputModel> groupOutputModels = new List <GroupOutputModel>();
            List <GroupDTO>         groups            = adm.GetAllGroups();

            if (groups == null)
            {
                return(BadRequest("Неверный запрос"));
            }
            else
            {
                foreach (GroupDTO g in groups)
                {
                    GroupOutputModel groupOutModel = new GroupOutputModel();
                    AdminDataAccess  gr            = new AdminDataAccess();
                    groupOutModel.Id        = g.Id;
                    groupOutModel.Name      = g.Name;
                    groupOutModel.StartDate = g.StartDate;
                    groupOutModel.EndDate   = g.EndDate;
                    List <UserDTO>         students    = gr.GetStudents(g.Id);
                    List <UserOutputModel> studentsOut = new List <UserOutputModel>();
                    foreach (UserDTO st in students)
                    {
                        UserMapper um = new UserMapper();
                        studentsOut.Add(um.ConvertUserDTOToUserOutputModel(st));
                    }
                    List <UserDTO>         teachers    = gr.GetTeacherByGroupId(g.Id);
                    List <UserOutputModel> teachersOut = new List <UserOutputModel>();
                    foreach (UserDTO tc in teachers)
                    {
                        UserMapper tm = new UserMapper();
                        teachersOut.Add(tm.ConvertUserDTOToUserOutputModel(tc));
                    }
                    groupOutModel.Students = studentsOut;
                    groupOutModel.Teachers = teachersOut;
                    groupOutputModels.Add(groupOutModel);
                }
                return(Ok(groupOutputModels));
            }
        }
Exemplo n.º 3
0
        public IActionResult GetGroupById(int groupId)
        {
            Mapper          mapper = new Mapper();
            AdminDataAccess adm    = new AdminDataAccess();
            GroupDTO        group  = adm.GetGroupById(groupId);

            if (group == null)
            {
                return(new BadRequestObjectResult("Запрашиваемой группы не существует"));
            }
            else
            {
                GroupOutputModel groupOutModel = new GroupOutputModel();
                AdminDataAccess  gr            = new AdminDataAccess();
                groupOutModel.Id        = group.Id;
                groupOutModel.Name      = group.Name;
                groupOutModel.StartDate = group.StartDate;
                groupOutModel.EndDate   = group.EndDate;
                List <UserDTO>         students    = gr.GetStudents(group.Id);
                List <UserOutputModel> studentsOut = new List <UserOutputModel>();
                foreach (UserDTO st in students)
                {
                    UserMapper um = new UserMapper();
                    studentsOut.Add(um.ConvertUserDTOToUserOutputModel(st));
                }
                List <UserDTO>         teachers    = gr.GetTeacherByGroupId(group.Id);
                List <UserOutputModel> teachersOut = new List <UserOutputModel>();
                foreach (UserDTO tc in teachers)
                {
                    UserMapper tm = new UserMapper();
                    teachersOut.Add(tm.ConvertUserDTOToUserOutputModel(tc));
                }
                groupOutModel.Students = studentsOut;
                groupOutModel.Teachers = teachersOut;
                return(Ok(groupOutModel));
            }
        }