Ejemplo n.º 1
0
        public static Survey Convert(SurveyInput input, int AuthorId)
        {
            var authorRepo = new UserDetailsRepository();
            var Author     = authorRepo.GetById(AuthorId);

            return(new Survey(input.Name, input.StartDate, input.EndDate, input.Description
                              , input.Options.Select(x => OptionInputConverter.Convert(x))
                              , Author, input.PhotoPath, input.Color));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get()
        {
            var token = HttpContext.Request.Headers["Authorization"].Last().Split(" ").Last();

            string[] roles = { "User", "Admin", "SchoolAdmin" };

            var repo        = new CandidacyRepository();
            var detailsRepo = new UserDetailsRepository();

            //Gets UserId(sub) fro token;
            var handler = new JwtSecurityTokenHandler();
            var sub     = handler.ReadJwtToken(token).Payload.Sub;

            var schoolId = detailsRepo.GetAll().First(x => x.UserId == sub).SchoolId;


            if (RoleService.CheckRoles(token, roles, _userManager))
            {
                var result = repo.GetAll().Where(x => detailsRepo.GetById(x.OwnerId.GetValueOrDefault()).SchoolId == schoolId).ToList();
                return(Ok(result));
            }

            return(Unauthorized());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// This method is used for retrieving UserDetail based on UserDetail Id
 /// </summary>
 /// <remarks>
 /// DateCreated: 24th Oct 2016
 /// Edited By: Rakesh (25-Oct-2016) , Phani (3-Nov-2016)
 /// </remarks>
 /// <param name="id">contains UserDetail Id</param>
 /// <returns>UserDetail</returns>
 public Userdetail GetById(int id)
 {
     return(objUserDetailsRepository.GetById(id));
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Get()
        {
            var token = HttpContext.Request.Headers["Authorization"].Last().Split(" ").Last();

            string[] roles = { "Admin", "SchoolAdmin" };

            if (RoleService.CheckRoles(token, roles, _userManager))
            {
                var repo    = new SchoolRepository();
                var userIds = repo.GetAll()
                              .Select(x => new
                {
                    Name    = x.Name,
                    UserIds = x.Users.Select(x => x.UserId)
                }).ToDictionary(x => x.Name, x => x.UserIds);

                var SchoolsUsers = new Dictionary <string, List <User> >();

                foreach (var school in userIds.Keys)
                {
                    SchoolsUsers.Add(school, userIds[school].Select(x => _userManager.FindByIdAsync(x).Result).ToList());
                }

                var detailsRepo = new UserDetailsRepository();


                //Produces summary for each school with summaries for each of students.
                var result = repo.GetAll().Select(x => new SchoolSummary(x.Id, x.Name, SchoolsUsers[x.Name]
                                                                         .Select(x => UserSummaryFactory.CreateSummary(detailsRepo.GetById(x.DetailsId), x)).ToList())).ToList();

                return(Ok(result));
            }

            return(Unauthorized("Only Admin and SchoolAdmin roles have permission to this controller."));
        }