public async Task <IActionResult> Login(
            [FromBody] LoginUserDto loginUserDto
            )
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest, "Incorrect object");
                }

                // Se utilizara el codigo en mayusculas
                loginUserDto.Username = loginUserDto.Username.ToUpper();
                loginUserDto.Password = loginUserDto.Password.ToUpper();

                var user = await _authService.LoginAsync(loginUserDto.Username, loginUserDto.Password);

                var jwtResponse = _jwtService.GenerateToken(user);

                return(Ok(jwtResponse));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> Register(
            [FromBody] RegisterUserDto registerUserDto
            )
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest, "Incorrect object");
                }

                registerUserDto.Username = registerUserDto.Username.ToUpper();
                registerUserDto.Password = registerUserDto.Password.ToUpper();

                var user = await _authService.RegisterAsync(registerUserDto.Username, registerUserDto.Password);

                var jwtResponse = _jwtService.GenerateToken(user);

                return(Ok(jwtResponse));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> GetAllNonActiveReservationsByUserIdAsync([FromBody] CancelReservationDTO cancelReservationDTO)
        {
            try
            {
                var response = await _reservationService.CancelReservation(cancelReservationDTO);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> GetByFilters([FromQuery] GetByFiltersRequestDto requestDto)
        {
            try
            {
                var response = await _publicationService.GetByFiltersAsync(requestDto);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> GetAllByCubicleIdAsync([FromRoute] int id)
        {
            try
            {
                var response = await _resourceService.GetAllByCubicleIdAsync(id);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> GetAll()
        {
            try
            {
                var response = await userService.GetAllAsync();

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #7
0
        public async Task <IActionResult> Create([FromBody] CreateRequestRequestDto requestDto)
        {
            try
            {
                var response = await requestService.CreateOneAsync(requestDto);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #8
0
        public async Task <IActionResult> GetAll()
        {
            try
            {
                var campusList = await _campusService.GetAllAsync();

                return(Ok(campusList));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #9
0
        public async Task <IActionResult> GetAllAsync()
        {
            try
            {
                var items = await _resourceTypeService.GetAllAsync();

                return(Ok(items));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #10
0
        public async Task <IActionResult> GetAllPendingAndAcceptedRequestByPublicationId([FromRoute] int publicationId)
        {
            try
            {
                var response = await requestService.GetAllPendingAndAcceptedRequestByPublicationId(publicationId);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #11
0
        public async Task <IActionResult> AnswerRequest([FromBody] AnswerRequestDTO requestDto)
        {
            try
            {
                var response = await requestService.answerRequest(requestDto);

                return(Ok());
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #12
0
        public async Task <IActionResult> CancelRequest([FromBody] CancelRequestDTO cancelRequest)
        {
            try
            {
                var response = await requestService.cancelRequest(cancelRequest);

                return(Ok());
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #13
0
        public async Task <IActionResult> ConfirmRequest([FromBody] ConfirmGuestDTORequest RequestDto)
        {
            try
            {
                var response = await requestService.ConfirmGuest(RequestDto);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #14
0
        public async Task <IActionResult> GetAllNonActiveReservationsByUserIdAsync([FromRoute] int id)
        {
            try
            {
                var response = await _pointsRecordService.FindAllAsync(id);

                return(Ok(response));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #15
0
 public IActionResult GetAllMyPendingAndAcceptedCurrentRequests(int id)
 {
     try
     {
         // var x = User.FindFirst(ClaimTypes.NameIdentifier);
         //var jwtUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
         var response = requestService.GetAllPendingAndAcceptedCurrentRequestsByUserId(id);
         return(Ok(response));
     }
     catch (Exception e)
     {
         return(HttpExceptionMapper.ToHttpActionResult(e));
     }
 }
        public async Task <IActionResult> GetAllByFiltersAsync(
            [FromQuery] CubicleFiltersDto filters
            )
        {
            try
            {
                var items = await _cubicleService.GetCubiclesByFiltersAsync(filters);

                return(Ok(items));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> GetOneByIdAsync(
            [FromRoute] int id
            )
        {
            try
            {
                var item = await userService.GetOneByIdAsync(id);

                return(Ok(item));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #18
0
        public async Task <IActionResult> CreateOneAsync(
            [FromBody] CreatePublicationDto createPublicationDto
            )
        {
            try
            {
                var created = await _publicationService.CreateOneAsync(createPublicationDto);

                return(Ok(created));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
Beispiel #19
0
        public async Task <IActionResult> FindAllByPublicationIdAsync(
            [FromRoute] int id
            )
        {
            try
            {
                var result = await _sharedSpaceService.FindAllByPublicationIdAsync(id);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> CreateOneAsync(
            [FromBody] CreateResourceDto resource
            )
        {
            try
            {
                var item = await _resourceService.CreateOneAsync(resource.ToEntity());

                return(Ok(item));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> ActiveReservation(
            [FromRoute] int id
            )
        {
            try
            {
                var reservation = await _reservationService.StopSharingReservationWithId(id);

                return(Ok(reservation));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
        public async Task <IActionResult> UpdateOneByIdAsync(
            [FromRoute] int id,
            [FromBody] UpdateResourceDto resource
            )
        {
            try
            {
                var item = await _resourceService.UpdateOneByIdAsync(id, resource.ToEntity());

                return(Ok(item));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }
 public async Task <IActionResult> UpdateOneByIdAsync(
     [FromRoute] int id,
     [FromBody] UpdateResourceDto resource
     )
 {
     try
     {
         // TODO: Implementar este metodo (by joaquincito tu estudiantito garcia)
         // var item = await _cubicleService
         //     .UpdateOneByIdAsync(id, resource.ToEntity());
         return(Ok(null));
     }
     catch (Exception e)
     {
         return(HttpExceptionMapper.ToHttpActionResult(e));
     }
 }
        public async Task <IActionResult> GetAllNonActiveReservationsByUserIdAsync(
            )
        {
            try
            {
                var    handler    = new JwtSecurityTokenHandler();
                string authHeader = Request.Headers["Authorization"];
                authHeader = authHeader.Replace("Bearer ", "");
                var jsonToken   = handler.ReadToken(authHeader);
                var tokenS      = handler.ReadToken(authHeader) as JwtSecurityToken;
                var nameId      = int.Parse(tokenS.Claims.First(claim => claim.Type == "nameid").Value);
                var reservation = await _reservationService.GetAllNonActiveReservationsByUserIdAsync(nameId);

                return(Ok(reservation));
            }
            catch (Exception e)
            {
                return(HttpExceptionMapper.ToHttpActionResult(e));
            }
        }