Exemplo n.º 1
0
        public static FaultException <ServiceErrorResponse> Generar(string strMensaje)
        {
            dynamic serviceErrorResponse = new ServiceErrorResponse();

            serviceErrorResponse.Message = strMensaje;
            throw new FaultException <ServiceErrorResponse>(serviceErrorResponse, new FaultReason(strMensaje));
        }
        public JsonResult CalculateBrutoNetto(dynamic parameters)
        {
            ServiceResponse response = default(ServiceResponse);

            using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name)))
            {
                try
                {
                    HttpRequestAgent connector = new HttpRequestAgent();
                    string           value     = connector.Post("https://brutnet.attentia.be/GetBrutoNettoBerekening?onlyValidate=true", parameters);
                    //string value = "{ \"Bruto\": \"2500.0\", \"Netto\": \"1250.00\" }";

                    if (string.IsNullOrEmpty(value))
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                    ResponseStatus status = string.IsNullOrEmpty(value) ? ResponseStatus.NO_DATA : ResponseStatus.OK;

                    response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, value);
                }
                catch (Exception ex)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex));
                }
            }

            return(this.Json(response));
        }
        public async Task <JsonResult> SignUpUser(OAuth2UserIdentity userIdentity)
        {
            ServiceResponse response = default(ServiceResponse);

            using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name)))
            {
                try
                {
                    IDataPortal        portal = DependencyInjection.Get <IDataPortal>();
                    OAuth2UserIdentity value  = portal.SignUpUser(userIdentity);

                    // Set the status on HTTP and response level.
                    if (value == null)
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                    ResponseStatus status = value == null ? ResponseStatus.NO_DATA : ResponseStatus.OK;

                    response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, value);
                }
                catch (Exception ex)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex));
                }
            }

            return(this.Json(response));
        }
        public async Task <JsonResult> GetUserProfile()
        {
            ServiceResponse response = default(ServiceResponse);

            using (Session session = ApplicationModel.Current.CreateSession(new SecurityToken(this.HttpContext.Request.Url.Host, this.HttpContext.User.Identity.Name)))
            {
                try
                {
                    string value = "HELLO WORLD 2.0";

                    // Set the status on HTTP and response level.
                    if (value == null)
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                    ResponseStatus status = value == null ? ResponseStatus.NO_DATA : ResponseStatus.OK;

                    response = new ServiceDataResponse(RestVersion0100Controller.API_VERSION, status, value);
                }
                catch (Exception ex)
                {
                    response = new ServiceErrorResponse(RestVersion0100Controller.API_VERSION, ResponseStatus.ERROR, new ServiceError(ex));
                }
            }

            return(this.Json(response, JsonRequestBehavior.AllowGet));
        }
 public IActionResult DeleteTaxonomy([FromRoute] int id)
 {
     try
     {
         _taxonomyUseCase.ExecuteDelete(id);
         return(Ok());
     }
     catch (InvalidOperationException e)
     {
         LoggingHandler.LogError(e.Message);
         LoggingHandler.LogError(e.StackTrace);
         return(BadRequest(
                    new ErrorResponse($"Error deleting taxonomy")
         {
             Status = "Bad request", Errors = new List <string> {
                 $"An error occurred attempting to delete taxonomy {id}: {e.Message}"
             }
         }));
     }
     catch (UseCaseException e)
     {
         return(BadRequest(e));
     }
     catch (ServiceTaxonomyExistsException ex)
     {
         var errorResponse = new ServiceErrorResponse
         {
             ErrorMessage = ex.DevErrorMessage,
             Services     = ex.Services
         };
         return(BadRequest(errorResponse));
     }
 }
Exemplo n.º 6
0
        private ServiceErrorResponse BuildErrorResponse(IServiceRequest request)
        {
            var response = new ServiceErrorResponse()
            {
                ServiceName = request.ServiceName,
                RequestId   = request.RequestId,
                Status      = false,
                ErrorCode   = 99,
                Message     = String.Format("Error while handling request for service: {0}", request.ServiceName)
            };

            return(response);
        }
Exemplo n.º 7
0
        public static ServiceErrorResponse UnAuthorized()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.Forbidden,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Unauthorized,
                    Message = "User is not authorized.",
                    Target  = "todoItem"
                }
            };

            return(error);
        }
Exemplo n.º 8
0
        public static ServiceErrorResponse AccessDenied()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.Forbidden,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Forbidden,
                    Message = $"No access to the requested resource.",
                    Target  = "toDoTask"
                }
            };

            return(error);
        }
Exemplo n.º 9
0
        public static ServiceErrorResponse IncorrectPassword()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.ValidationError,
                    Message = $"Wrong password entered.",
                    Target  = "password"
                }
            };

            return(error);
        }
Exemplo n.º 10
0
        public static ServiceErrorResponse InvalidRouteParameter(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "Route parameter is null or has inappropriate form.",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 11
0
        public static ServiceErrorResponse NoSuchObject(string target, string message)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.NotFound,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.NotFound,
                    Message = message,
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 12
0
        public static ServiceErrorResponse InvalidClaims(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "JWT has invalid claims",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 13
0
        public static ServiceErrorResponse InvalidQuery(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "Request query parameters are invalid.",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 14
0
        public static ServiceErrorResponse ToDoAlreadyExists(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Forbidden,
                    Message = "ToDo already exists.",
                    Target  = target
                }
            };

            return(error);
        }
        public static ServiceErrorResponse ValidationError(string target, string message)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.ValidationError,
                    Message = message,
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 16
0
        public static ServiceErrorResponse AuthIsNotConfirmed(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.Unauthorized,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Forbidden,
                    Message = "Authorization forbidden",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 17
0
        public static ServiceErrorResponse Forbidden()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.Forbidden,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Forbidden,
                    Message = "Access is forbidden.",
                    Target  = "user"
                }
            };

            return(error);
        }
Exemplo n.º 18
0
        public static ServiceErrorResponse BodyIsMissingOrUncorrect(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "Request body is empty or uncorrect.",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 19
0
        public static ServiceErrorResponse Unauthenticated()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.Unauthorized,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Unauthorized,
                    Message = "User is not unauthorized.",
                    Target  = "user"
                }
            };

            return(error);
        }
Exemplo n.º 20
0
        public static ServiceErrorResponse UserIdIsNull()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "User Id is null.",
                    Target  = "user"
                }
            };

            return(error);
        }
Exemplo n.º 21
0
        public static ServiceErrorResponse NotEnoughUserData()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.ValidationError,
                    Message = $"Username and / or password are not entered.",
                    Target  = "user"
                }
            };

            return(error);
        }
Exemplo n.º 22
0
        public static ServiceErrorResponse ConflictLogin(string login)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.Conflict,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Conflict,
                    Message = $"User with such login: \"{login}\" already exist.",
                    Target  = "user"
                }
            };

            return(error);
        }
        public static ServiceErrorResponse InvalidImageData(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "Image must has PNG or JPG format and be less than 512 KB.",
                    Target  = target
                }
            };

            return(error);
        }
        public static ServiceErrorResponse InvalidCredentialsError(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.InvalidCredentials,
                    Message = "Username or password is incorrect.",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 25
0
        public static ServiceErrorResponse UserNotFound()
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.ValidationError,
                    Message = $"There is no user with this login or password.",
                    Target  = "user"
                }
            };

            return(error);
        }
        public static ServiceErrorResponse UnauthorizedError(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.Unauthorized,
                    Message = "You must be authorized. Access prohibited.",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 27
0
        public static ServiceErrorResponse BodyIsMissing(string target)
        {
            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = "Request body is empty or has inappropriate form.",
                    Target  = target
                }
            };

            return(error);
        }
Exemplo n.º 28
0
        public static ServiceErrorResponse TodoNotFound(string activityId)
        {
            if (activityId == null)
            {
                throw new ArgumentNullException(nameof(activityId));
            }

            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.NotFound,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.NotFound,
                    Message = $"An activity with \"{activityId}\" not found.",
                    Target  = "activity"
                }
            };

            return(error);
        }
Exemplo n.º 29
0
        public static ServiceErrorResponse ItemNotFound(string itemId)
        {
            if (itemId == null)
            {
                throw new ArgumentNullException(nameof(itemId));
            }

            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.NotFound,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.NotFound,
                    Message = $"A ToDo item with \"{itemId}\" not found.",
                    Target  = "ToDoItem"
                }
            };

            return(error);
        }
Exemplo n.º 30
0
        public static ServiceErrorResponse UserNameAlreadyExists(string userName)
        {
            if (userName == null)
            {
                throw new ArgumentNullException(nameof(userName));
            }

            var error = new ServiceErrorResponse
            {
                StatusCode = HttpStatusCode.BadRequest,
                Error      = new ServiceError
                {
                    Code    = ServiceErrorCodes.BadRequest,
                    Message = $"User \"{userName}\" already exists.",
                    Target  = userName
                }
            };

            return(error);
        }
Exemplo n.º 31
0
 public int IndexOf(ServiceErrorResponse value)
 {
     return a.IndexOf(value);
 }
Exemplo n.º 32
0
 public bool Contains(ServiceErrorResponse value)
 {
     return a.Contains(value);
 }
Exemplo n.º 33
0
 public void Remove(ServiceErrorResponse value)
 {
     a.Remove(value);
 }
Exemplo n.º 34
0
 public int Add(ServiceErrorResponse value)
 {
     return a.Add(value);
 }
Exemplo n.º 35
0
 public void Insert(int index, ServiceErrorResponse value)
 {
     a.Insert(index, value);
 }