Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> cancelRequest(CancelRequestDTO cancel)
        {
            var request = await requestRepository.GetOneByIdAsync(cancel.RequestId);

            if (request == null)
            {
                throw new BadRequestException($"Request with id {cancel.RequestId} was not found");
            }
            if (request.ConstantId == RequestStatus.Denied)
            {
                throw new BadRequestException($"Request with id {cancel.RequestId} is denied");
            }
            if (request.ConstantId == RequestStatus.Confirmed)
            {
                throw new BadRequestException($"Request with id {cancel.RequestId} is confirmed");
            }
            if (request.ConstantId == RequestStatus.Canceled)
            {
                throw new BadRequestException($"Request with id {cancel.RequestId} is canceled");
            }
            request.ConstantId = RequestStatus.Canceled;
            if (request.ConstantId != RequestStatus.Accepted)
            {
                await requestRepository.UpdateOneAsync(request);
            }
            else
            {
                Console.WriteLine("Requeste aceptado");
                SharedSpace sharedSpace = await sharedSpaceRepository.FindOneByIdAsync(request.SharedSpaceId);

                sharedSpace.IsOccupied = false;
                await requestRepository.UpdateOneAsync(request);

                await sharedSpaceRepository.UpdateAsync(sharedSpace);

                Console.WriteLine("ShareSpace ya no ocupado");
            }



            return(true);
        }