Esempio n. 1
0
        public HttpResponseMessage Delete(string ticket, int itemId)
        {
            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var deleteRequest = new DeleteItemRequest
            {
                ItemId = itemId,
                UserId = sessionInfo.User.Id,
            };

            var handler = new DeleteItemHandler(_connectionString);

            var response = handler.Handle(deleteRequest);

            var httpStatusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(httpStatusCode, response));
        }
Esempio n. 2
0
        public HttpResponseMessage GetList(int dashboardId, string ticket)
        {
            // Call security provider to check if session is valid

            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var getListRequest = new GetItemsListRequest
            {
                DashboardId = dashboardId,
                User        = sessionInfo.User
            };

            var handler = new GetItemsListHandler(_connectionString);

            var response = handler.Handle(getListRequest);

            var httpStatusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(httpStatusCode, response));
        }
        public HttpResponseMessage Create(string ticket, string dashName)
        {
            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var deleteRequest = new CreateDashboardRequest
            {
                DashName = dashName,
                UserId   = sessionInfo.User.Id
            };

            var handler = new CreateDashboardHandler(_connectionString);

            var response = handler.Handle(deleteRequest);

            var statusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(statusCode, response));
        }
        public HttpResponseMessage Update(string ticket, DashBoard dash)
        {
            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var updateRequest = new UpdateDashboardRequest
            {
                DashBoard = dash, //TODO FIX HERE
                UserId    = sessionInfo.User.Id
            };

            var handler = new UpdateDashBoardHandler(_connectionString);

            var response = handler.Handle(updateRequest);

            var statusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(statusCode, response));
        }
Esempio n. 5
0
        public HttpResponseMessage LogOut(string ticket)
        {
            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var logOutRequest = new LogoutUserRequest
            {
                UserId = sessionInfo.User.Id
            };

            var handler = new LogoutUserHandler(_connectionString);

            var response = handler.Handle(logOutRequest);

            var httpStatusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(httpStatusCode));
        }
        public HttpResponseMessage GetList(string ticket)
        {
            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            var getListRequest = new GetDashboardsRequest
            {
                Id = sessionInfo.User.Id
            };

            var handler = new GetDashboardsHandler(_connectionString);

            var response = handler.Handle(getListRequest);

            var statusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(statusCode, response));
        }
Esempio n. 7
0
        public HttpResponseMessage Update(User user, string ticket) //done, should i check if only id recieved?
        {
            var securityProvider = new SecurityProvider(_connectionString);

            var sessionInfo = securityProvider.GetSessionInfo(ticket);

            if (sessionInfo == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
            var updateRequest = new UpdateUserRequest
            {
                UserToUpdate = user,
                UserOrigin   = sessionInfo.User,
            };

            var handler = new UpdateUserHandler(_connectionString);

            var response = handler.Handle(updateRequest);

            var statusCode = ResolveStatusCode(response);

            return(Request.CreateResponse(statusCode, response));
        }