public async Task <List <TicketList> > UserTickets([FromQuery] bool archieve = false) { var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (claimId == 0) { return(null); } return(await _ticketService.GetUserTickets(archieve, claimId)); }
public async Task <IActionResult> CreateOrganizator([FromForm] OrganizatorResource resource) { var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (claimId == 0) { return(Unauthorized("You don't have permission to create a new organization")); } resource.CreatorId = claimId; var user = await _userRepository.GetUserByIdAsync(resource.CreatorId); if (user is null) { return(NotFound("There was an error with your account")); } var result = await _organizatorService.CreateNewOrganizator(resource); if (result is null) { return(BadRequest("There was an unexpected error while creating an organization")); } return(Ok("New organizator has been created")); }
public async Task <IActionResult> GenerateTokenAsync() { var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (claimId == 0) { return(Unauthorized("You don't have permission to create a place")); } var t = _tokenGeneratorService.GenerateJwtToken(claimId); return(Ok(t)); }
public async Task <IActionResult> Index() { var userId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (userId == 0) { return(Unauthorized("You don't have permission to get an organizations list")); } var organizators = await _administratorService.GetOrganizatorSelectsAsync(userId); if (organizators is null) { return(NotFound("User is not an administrator of any organization")); } return(Ok(organizators)); }
public async Task <IActionResult> Index([FromForm] EventResource resource) { if (!ModelState.IsValid) { return(BadRequest()); } var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (claimId == 0) { return(Unauthorized("You don't have permission to create a place")); } resource.UserId = claimId; var isAdminOfOrganization = await _administratorRepository.IsUserAdministratorOfOrganizator(resource.UserId, resource.OrganizatorId); if (!isAdminOfOrganization) { return(NotFound("You are not an administrator of this organizator")); } var isPlaceExists = await _placeRepository.IsPlaceExistsInOrganizator(resource.OrganizatorId, resource.PlaceId); if (!isPlaceExists) { return(NotFound("Place doesn't exists or is not connected with organizator")); } var isEventDateCollision = _eventRepository.IsEventDateCollision(resource.BeginDate, resource.FinishDate, resource.PlaceId); if (isEventDateCollision) { return(BadRequest("There is other event in this place between your dates")); } await _eventService.AddEvent(resource); return(Ok("Event has been created")); }
public async Task <IActionResult> IndexAsync([FromForm] CreatePlaceResource resource) { if (!ModelState.IsValid) { return(BadRequest()); } var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (claimId == 0) { return(Unauthorized("You don't have permission to create a place")); } resource.UserId = claimId; var isAdminOfOrganization = await _administratorRepository.IsUserAdministratorOfOrganizator(resource.UserId, resource.OrganizatorId); if (!isAdminOfOrganization) { return(NotFound("You are not an administrator of this organizator")); } var isPlaceExists = await _placeRepository.IsPlaceExistsInOrganizator(resource.OrganizatorId, resource.PlaceName); if (isPlaceExists) { return(BadRequest("Place with this name already exists in this organizator")); } var IsSuccess = await _placeService.AddPlace(resource); if (IsSuccess) { return(Ok("Place was created")); } return(BadRequest("There was an unexpected error while creating place")); }
public string GetUserId() { return(_claimsService.GetUserId(HttpContext.User)); }
public string GetUserId(AuthorizationHandlerContext context) { return(_claimsService.GetUserId(context)); }
public string GetUserId() { return(_claimsService.GetUserId(_httpContextAccessor.HttpContext.User)); }