示例#1
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));
        }
        private IList <ErrorStatus> Validate(GetItemsListRequest request)
        {
            var errors = new List <ErrorStatus>();


            var requestUser = request.User;

            var ownerUser = _dashRepository.GetUserByDashId(request.DashboardId);

            if (requestUser == null || ownerUser == null)
            {
                errors.Add(new ErrorStatus("WRONG_REQUEST"));
                return(errors);
            }


            if (requestUser.Id != ownerUser.Id)
            {
                errors.Add(new ErrorStatus("UNAUTHORIZED_ACESS"));
                return(errors);
            }



            return(errors);
        }
示例#3
0
        public ExecuteResult <ItemsCollectionResponse> GetProductList(GetItemsListRequest request)
        {
            var r = Get(request.Version, request.PagerRequest, request.Timestamp, request.UserModel.Id);


            var result = new ExecuteResult <ItemsCollectionResponse>
            {
                Data = r
            };

            return(result);
        }
示例#4
0
        public ActionResult List(GetItemsListRequest request, int?authUid, UserModel authUser, [FetchUser(KeyName = "userid", IsCanMissing = true)] UserModel showUser)
        {
            if (showUser == null && authUid == null && authUser == null)
            {
                return(new RestfulResult
                {
                    Data = new ExecuteResult
                    {
                        StatusCode = StatusCode.ClientError,
                        Message = "用户参数错误"
                    }
                });
            }

            request.UserModel = showUser ?? authUser;

            return(new RestfulResult {
                Data = _itemsDataService.GetProductList(request)
            });
        }
        public GetItemsListResponse Handle(GetItemsListRequest request) //TODO need to check for null
        {
            var response = new GetItemsListResponse();

            response.Errors = Validate(request);

            if (response.HasErrors)
            {
                return(response);
            }
            try
            {
                var items = _itemsRepository.GetByDashboardId(request.DashboardId);

                var itemsWithScreenshots = new List <Item>();

                foreach (var item in items)
                {
                    var screenshots = _screenshotRepository.GetLastsByItemId(item.Id, 15);

                    if (screenshots.Count > 0)
                    {
                        item.Screenshots = screenshots;
                    }

                    itemsWithScreenshots.Add(item);
                }

                response.Items = itemsWithScreenshots;

                return(response);
            }
            catch (Exception)
            {
                response.Errors.Add(new ErrorStatus("BAD_REQUEST"));
                return(response);
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            //获取商店信息
            //ShopInfoRequest request = new ShopInfoRequest
            //{
            //    Partner_id = partner_id,
            //    Shopid = shopid
            //};



            GetItemsListRequest request = new GetItemsListRequest
            {
                Pagination_Offset           = 0,
                Pagination_Entries_Per_Page = 100,
                Partner_ID = partner_id,
                ShopID     = shopid
            };
            var response = WebUtils.DoExecute(request);

            if (response != null && !string.IsNullOrEmpty(response.error))
            {
            }
        }