Example #1
0
        public async Task <ActionResult> CreateAsync([FromForm] EventCreateDto eventCreateDto)
        {
            _logger.LogMethodCallingWithObject(eventCreateDto);

            var hostRoot = _hostServices.GetHostPath();

            await _eventManager.AddEventAsync(eventCreateDto, hostRoot);

            return(Ok());
        }
Example #2
0
 public async Task <ActionResult> Create([FromForm] PostCreateDto PostCreateDto)
 {
     return(await HandleExceptions(async() =>
     {
         if (ModelState.IsValid)
         {
             var hostRoot = _hostServices.GetHostPath();
             await _postManager.AddPostAsync(PostCreateDto, hostRoot);
             return Ok();
         }
         return BadRequest("Model state is not valid");
     }));
 }
Example #3
0
 public async Task <ActionResult <UserToUpdateDto> > Update(int userId)
 {
     return(await HandleExceptions(async() =>
     {
         var role = User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimsIdentity.DefaultRoleClaimType))?.Value;
         var currentUserId = User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimsIdentity.DefaultNameClaimType))?.Value;
         if (role != "Admin" && Int32.Parse(currentUserId) != userId)
         {
             return Forbid("Access denied");
         }
         var hostRoot = _hostServices.GetHostPath();
         return Ok(await _userManager.GetUserToUpdateAsync(userId));
     }));
 }
Example #4
0
        public async Task <ActionResult <UserToUpdateDto> > UpdateAsync(string userId)
        {
            _logger.LogMethodCallingWithObject(new { userId });
            var role          = User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimsIdentity.DefaultRoleClaimType))?.Value;
            var currentUserId = User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimsIdentity.DefaultNameClaimType))?.Value;

            if (Equals(role, "Admin") && !Equals(currentUserId, userId))
            {
                return(Forbid("Access denied"));
            }
            var hostRoot = _hostServices.GetHostPath();

            return(Ok(await _userManager.GetUserToUpdateAsync(Guid.Parse(userId))));
        }