Exemplo n.º 1
0
        public HttpResponseMessage GetBulkPricePreviewItems(
            [FromUri] string officeNumber,
            [FromUri] string fromPriceList,
            [FromUri] string toPriceList,
            [FromUri] string changeTypeValue,
            [FromUri] bool changeTypePercentage,
            [FromUri] string dollarAmount,
            [FromUri] bool dollarAdd,
            [FromUri] string rounding,
            [FromUri] bool activeOnly,
            [FromUri] bool all,
            List <int> collectionIds,
            [FromUri] int pageSize         = 20,
            [FromUri] int pageStart        = 0,
            [FromUri] string sortCol       = null,
            [FromUri] string sortDirection = null)
        {
            if (string.IsNullOrEmpty(fromPriceList) || string.IsNullOrEmpty(toPriceList) || (collectionIds == null))
            {
                return(Request.CreateResponse(HttpStatusCode.ExpectationFailed));
            }

            var items = this.productsManager.GetBulkPricing(
                this.companyId,
                fromPriceList,
                changeTypeValue,
                changeTypePercentage,
                dollarAmount,
                dollarAdd,
                rounding,
                activeOnly,
                collectionIds,
                pageSize,
                pageStart,
                sortCol,
                sortDirection);

            var frameBulkPrices = items as IList <FrameBulkPrice> ?? items.ToList();
            var firstOrDefault  = frameBulkPrices.FirstOrDefault();
            var totalCount      = 0;

            if (firstOrDefault != null)
            {
                totalCount = firstOrDefault.TotalRowNum;
            }

            var res = new Model.PagedResult <FrameBulkPrice>
            {
                PageSize     = pageSize,
                CurrentPage  = pageStart / pageSize,
                TotalCount   = totalCount,
                CurrentItems = frameBulkPrices.ToArray()
            };

            return(Request.CreateResponse(
                       HttpStatusCode.OK,
                       new
            {
                PreviewItems = res,
            }));
        }
Exemplo n.º 2
0
        public HttpResponseMessage GetFrameItems(
            string officeNumber,
            string collectionId,
            string styleId,
            string searchText,
            bool activeOnly,
            [FromUri] int pageSize         = 20,
            [FromUri] int pageStart        = 0,
            [FromUri] string sortCol       = null,
            [FromUri] string sortDirection = null)
        {
            bool?active = null;

            int?frameCollectionId = null;

            if (!string.IsNullOrEmpty(collectionId))
            {
                frameCollectionId = Convert.ToInt32(collectionId);
            }

            int?frameStyleId = null;

            if (!string.IsNullOrEmpty(styleId))
            {
                frameStyleId = Convert.ToInt32(styleId);
            }

            if (activeOnly)
            {
                active = true;
            }

            if (frameCollectionId == null && string.IsNullOrEmpty(searchText))
            {
                var res = new Model.PagedResult <FrameSetup>
                {
                    PageSize     = pageSize,
                    CurrentPage  = pageStart / pageSize,
                    TotalCount   = 0,
                    CurrentItems = new List <FrameSetup>().ToArray()
                };

                return(this.Request.CreateResponse(HttpStatusCode.OK, new { FrameSetupItems = res, HasCustomFrame = false }));
            }

            var sortDir = "ASC";

            if (!string.IsNullOrEmpty(sortDirection))
            {
                if (sortDirection == "Descending")
                {
                    sortDir = "DESC";
                }
            }

            int totalRecords;
            var items          = this.frameIt2Manager.GetFrameItems(this.companyId, frameCollectionId, frameStyleId, searchText, active.GetValueOrDefault(), out totalRecords, this.dataSourceId, pageSize, pageStart, sortCol, sortDir);
            var hasCustomFrame = false;

            if (items != null && items.Any())
            {
                var res = new Model.PagedResult <FrameSetup>
                {
                    PageSize     = pageSize,
                    CurrentPage  = pageStart / pageSize,
                    TotalCount   = items.Count,
                    CurrentItems = items.Where((t, i) => i >= pageStart && i < pageStart + pageSize).ToArray() //// items.ToArray(),
                };

                if (items.Any(item => item.IsCustomFrame == true))
                {
                    hasCustomFrame = true;
                }

                return(this.Request.CreateResponse(
                           HttpStatusCode.OK,
                           new
                {
                    FrameSetupItems = res, HasCustomFrame = hasCustomFrame
                }));
            }

            var result = new Model.PagedResult <FrameSetup>
            {
                PageSize     = pageSize,
                CurrentPage  = pageStart / pageSize,
                TotalCount   = totalRecords,
                CurrentItems = new List <FrameSetup>().ToArray()
            };

            if (totalRecords != 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.RequestedRangeNotSatisfiable, totalRecords.ToString(CultureInfo.InvariantCulture)));
            }

            return(this.Request.CreateResponse(HttpStatusCode.OK, new { FrameSetupItems = result, HasCustomFrame = false }));
        }