Esempio n. 1
0
 public BaseResponse <List <CategoryResponse> > GetAll([FromHeader] Guid UserID)
 {
     return(BaseResponse <List <CategoryResponse> > .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                categoryService.GetAllCategories(UserID)));
 }
 public BaseResponse <VotingItemResponse> CastVote([FromBody] VoteRequest request, [FromHeader] Guid UserID)
 {
     return(BaseResponse <VotingItemResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                voteService.VoteForItem(request, UserID)));
 }
Esempio n. 3
0
 public BaseResponse <CategoryResponse> DeleteCategory(Guid id, [FromHeader] Guid UserID)
 {
     return(BaseResponse <CategoryResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                categoryService.DeleteCategory(id, UserID)));
 }
Esempio n. 4
0
 public BaseResponse <AccountLogoutResponse> LogoutAccount([FromBody] AccountLogoutRequest request, [FromHeader] Guid SessionID)
 {
     return(BaseResponse <AccountLogoutResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                accountService.LogoutAccount(request, SessionID)));
 }
Esempio n. 5
0
 public BaseResponse <CategoryResponse> UpdateCategory([FromBody] CategoryUpdateRequest request, [FromHeader] Guid UserID)
 {
     return(BaseResponse <CategoryResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                categoryService.UpdateCategory(request, UserID)));
 }
 public BaseResponse <List <VotingItemResponse> > GetAllVotingItem()
 {
     return(BaseResponse <List <VotingItemResponse> > .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                votingItemService.GetAllVotingItem()));
 }
        public static void ConfigureExceptionHandler(this IApplicationBuilder app, ILoggerManager logger)
        {
            app.UseExceptionHandler(appError =>
            {
                appError.Run(async context =>
                {
                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    context.Response.ContentType = "application/json";

                    var contextFeature = context.Features.Get <IExceptionHandlerFeature>();
                    if (contextFeature != null)
                    {
                        logger.LogError($"Something went wrong: {contextFeature.Error}");

                        if (contextFeature.Error.GetType().Name.Equals("BusinessLogicException"))
                        {
                            BusinessLogicException businessLogicException = (BusinessLogicException)contextFeature.Error.GetBaseException();
                            await context.Response.WriteAsync(BaseResponse <String> .ConstructResponse(
                                                                  Status: businessLogicException.Code,
                                                                  Message: businessLogicException.ErrorMessage,
                                                                  null
                                                                  ).ToString());
                        }
                        else
                        {
                            await context.Response.WriteAsync(BaseResponse <String> .ConstructResponse(
                                                                  Status: HttpStatusCode.InternalServerError,
                                                                  Message: "Internal Server Error",
                                                                  null
                                                                  ).ToString());
                        }
                    }
                });
            });
        }
 public BaseResponse <VotingItemResponse> GetVotingItem(Guid id, [FromHeader] Guid UserID)
 {
     return(BaseResponse <VotingItemResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                votingItemService.GetVotingItem(id, UserID)));
 }
 public BaseResponse <VotingItemResponse> CreateVotingItem([FromBody] VotingItemCreationRequest request, [FromHeader] Guid UserID)
 {
     return(BaseResponse <VotingItemResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                votingItemService.CreateVotingItem(request, UserID)));
 }
 public BaseResponse <PrivilegeResponse> CheckPrivilege([FromBody] PrivilegeRequest request)
 {
     return(BaseResponse <PrivilegeResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                privilegeService.CheckPrivilige(request)));
 }
 public BaseResponse <VotingItemResponse> GetVotingItemById(Guid id)
 {
     return(BaseResponse <VotingItemResponse> .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                searchService.GetById(id)));
 }
 public BaseResponse <List <GenderResponse> > GetAll()
 {
     return(BaseResponse <List <GenderResponse> > .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                genderService.GetAllGenders()));
 }
 public BaseResponse <PagingResponse <VotingItemResponse> > SearchVotingItem(
     [FromQuery] VotingItemSearchParameter parameter, [FromHeader] Guid UserID)
 {
     return(BaseResponse <PagingResponse <VotingItemResponse> > .ConstructResponse(
                HttpStatusCode.OK,
                HttpStatusCode.OK.ToString(),
                constructPagingResponse(votingItemService.SearchVotingItem(parameter, UserID))));
 }
        private HttpResponseMessage ConstructErrorMessage(HttpStatusCode code, String error, HttpRequest request)
        {
            BaseResponse <String> content = BaseResponse <String>
                                            .ConstructResponse(code, error, null);

            HttpResponseMessage errorMessage = new HttpResponseMessage
            {
                StatusCode = code,
                Content    = new StringContent(content.ToString())
            };

            request.HttpContext.Response.StatusCode = (int)code;
            return(errorMessage);
        }
Esempio n. 15
0
        public BaseResponse <SessionResponse> CreateSessions()
        {
            String     remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
            String     ua        = Request.Headers["User-Agent"].ToString();
            ClientInfo c         = uaParser.Parse(Request.Headers["User-Agent"].ToString());
            String     userAgent = constructUserAgent(c, ua);

            SessionResponse response = sessionService.CreateSession(remoteIpAddress, userAgent);

            HttpContext.Response.Cookies.Append(
                "SessionID",
                response.SessionId.ToString(),
                new CookieOptions()
            {
                Path = "/", MaxAge = DateTime.Now.AddDays(1).TimeOfDay
            }
                );

            return(BaseResponse <SessionResponse> .ConstructResponse(
                       HttpStatusCode.OK,
                       HttpStatusCode.OK.ToString(),
                       response));
        }