public IHttpActionResult DeleteLot([FromBody, Required] LotDeletionDTO request)
        {
            using (var dbcontext = new UserContext())
            {
                LotManagementManager lotManagementManager = new LotManagementManager(dbcontext);

                try
                {
                    ResponseDTO <Boolean> response = lotManagementManager.DeleteLot(request);
                    if (response.Data == true)
                    {
                        return(Ok(response.Data));
                    }
                    else
                    {
                        ResponseDTO <HttpStatusCode> statusResponse = ResponseManager.ConvertErrorToStatus(response.Error);
                        return(Content(statusResponse.Data, statusResponse.Error));
                    }
                }
                catch (Exception e)
                {
                    return(Content((HttpStatusCode)400, e.Message));
                }
            }
        }
Exemplo n.º 2
0
 public ResponseDTO <Boolean> DeleteLot(LotDeletionDTO request)
 {
     try
     {
         var token = request.Token;
         ResponseDTO <Session> SessionDTO = _sessionServices.GetSession(new Guid(token));
         if (SessionDTO.Data != null)
         {
             AuthorizationClient authorizationClient = new AuthorizationClient();
             List <ClaimDTO>     functionClaims      = new List <ClaimDTO>()
             {
                 new ClaimDTO(new Claim("Action", "DeleteParkingLot"))
             };
             var username = SessionDTO.Data.UserAccount.Username;
             ResponseDTO <Boolean> authCheck = authorizationClient.Authorize(username, functionClaims);
             if (authCheck.Data == true)
             {
                 var lotname = request.LotName;
                 ResponseDTO <Boolean> response = _lotManagementService.DeleteLot(new Guid(lotname));
                 _loggerService.LogAction(LogConstants.ACTION_DELETE_LOT, SessionDTO.Data.Id.ToString(), SessionDTO.Data.SessionId.ToString());
                 return(response);
             }
             else
             {
                 return(new ResponseDTO <Boolean>()
                 {
                     Data = false,
                     Error = ErrorStrings.UNAUTHORIZED_ACTION
                 });
             }
         }
         else
         {
             return(new ResponseDTO <Boolean>()
             {
                 Data = false,
                 Error = ErrorStrings.SESSION_EXPIRED
             });
         }
     }
     catch (Exception e)
     {
         return(new ResponseDTO <Boolean>()
         {
             Data = false,
             Error = "[LOT MANAGEMENT MANAGER] Could not delete lot. " + e.ToString()
         });
     }
 }