Пример #1
0
        public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(coreModel.SearchCriteria))
            {
                return(false);
            }

            var qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query as string);

            var result = new coreModel.SearchCriteria();

            result.Keyword = qs["q"].EmptyToNull();
            var respGroup = qs["respGroup"].EmptyToNull();

            if (respGroup != null)
            {
                result.ResponseGroup = EnumUtility.SafeParse <coreModel.ResponseGroup>(respGroup, coreModel.ResponseGroup.Default);
            }
            result.StoreId       = qs["site"].EmptyToNull();
            result.CustomerId    = qs["customer"].EmptyToNull();
            result.Count         = qs["count"].TryParse(20);
            result.Start         = qs["start"].TryParse(0);
            bindingContext.Model = result;
            return(true);
        }
        private coreModel.SearchCriteria FilterOrderSearchCriteria(string userName, coreModel.SearchCriteria criteria)
        {
            if (!_securityService.UserHasAnyPermission(userName, null, OrderPredefinedPermissions.Read))
            {
                //Get defined user 'read' permission scopes
                var readPermissionScopes = _securityService.GetUserPermissions(userName)
                                           .Where(x => x.Id.StartsWith(OrderPredefinedPermissions.Read))
                                           .SelectMany(x => x.AssignedScopes);

                //Check user has a scopes
                //Stores
                criteria.StoreIds = readPermissionScopes.OfType <OrderStoreScope>()
                                    .Select(x => x.Scope)
                                    .Where(x => !String.IsNullOrEmpty(x))
                                    .ToArray();

                var responsibleScope = readPermissionScopes.OfType <OrderResponsibleScope>().FirstOrDefault();
                //employee id
                if (responsibleScope != null)
                {
                    criteria.EmployeeId = userName;
                }
            }
            return(criteria);
        }
		public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext)
		{
			if (bindingContext.ModelType != typeof(coreModel.SearchCriteria))
			{
				return false;
			}

			var qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query as string);

			var result = new coreModel.SearchCriteria();

			result.Keyword = qs["q"].EmptyToNull();
			var respGroup = qs["respGroup"].EmptyToNull();
			if (respGroup != null)
			{
				result.ResponseGroup = EnumUtility.SafeParse<coreModel.ResponseGroup>(respGroup, coreModel.ResponseGroup.Default);
			}
			result.StoreIds = qs.GetValues("stores");
			result.CustomerId = qs["customer"].EmptyToNull();
            result.EmployeeId = qs["employee"].EmptyToNull();
			result.Count = qs["count"].TryParse(20);
			result.Start = qs["start"].TryParse(0);
			bindingContext.Model = result;
			return true;
		}
        public IHttpActionResult Search([ModelBinder(typeof(SearchCriteriaBinder))] coreModel.SearchCriteria criteria)
        {
            //Scope bound ACL filtration
            criteria = FilterOrderSearchCriteria(HttpContext.Current.User.Identity.Name, criteria);

            var retVal = _searchService.Search(criteria);

            return(Ok(retVal.ToWebModel()));
        }
        public IHttpActionResult GetNewOrders(string action, string start_date, string end_date, int page)
        {
            if (action == "export")
            {
                var shipstationOrders = new Orders();

                var searchCriteria = new SearchCriteria
                {
                    ResponseGroup = ResponseGroup.Full
                };

                if (start_date != null)
                    searchCriteria.StartDate = DateTime.Parse(start_date, new CultureInfo("en-US"));

                if (end_date != null)
                    searchCriteria.EndDate = DateTime.Parse(end_date, new CultureInfo("en-US"));

                //if page more than 1 shipstation requests second or later page to be returned. move start position to that page.
                if (page > 1)
                {
                    searchCriteria.Start += searchCriteria.Count * (page - 1);
                }

                var searchResult = _orderSearchService.Search(searchCriteria);

                if (searchResult.CustomerOrders != null && searchResult.CustomerOrders.Any())
                {
                    var shipstationOrdersList = new List<OrdersOrder>();
                    searchResult.CustomerOrders.ForEach(cu => shipstationOrdersList.Add(cu.ToShipstationOrder()));
                    shipstationOrders.Order = shipstationOrdersList.ToArray();

                    //if first page was requested and total orders more than returned add to response overall pages count that shipstation should request.
                    if ((page == 1) && searchResult.TotalCount > searchCriteria.Count)
                    {
                        shipstationOrders.pages = (short)(searchResult.TotalCount / searchCriteria.Count);
                        shipstationOrders.pages += (short)(searchResult.TotalCount % searchCriteria.Count == 0 ? 0 : 1);
                        shipstationOrders.pagesSpecified = true;
                    }
                }

                return Ok(shipstationOrders);
            }

            return BadRequest();
        }
		public SearchResult Search(SearchCriteria criteria)
		{
			SearchResult retVal = null;
			using (var repository = _orderRepositoryFactory())
			{
				var query = repository.CustomerOrders;
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Number.Contains(criteria.Keyword) || x.CustomerName.Contains(criteria.Keyword));
                }
                
                if (criteria.CustomerId != null)
				{
					query = query.Where(x => x.CustomerId == criteria.CustomerId);
				}
				if (criteria.StoreIds != null && criteria.StoreIds.Any())
				{
					query = query.Where(x => criteria.StoreIds.Contains(x.StoreId));
				}
                if (criteria.EmployeeId != null)
                {
                    query = query.Where(x => x.EmployeeId == criteria.EmployeeId);
                }
                if (criteria.StartDate != null)
                {
                    query = query.Where(x => x.CreatedDate >= criteria.StartDate);
                }

                if (criteria.EndDate != null)
                {
                    query = query.Where(x => x.CreatedDate <= criteria.EndDate);
                }

				if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts)
				{
					query = query.Include(x => x.Discounts);
				}

				if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses)
				{
					query = query.Include(x => x.Addresses);
				}

				if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems)
				{
					query = query.Include(x => x.Items);

					if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts)
					{
						query = query.Include(x => x.Items.Select(y=>y.Discounts));
					}
				}

				if ((criteria.ResponseGroup & ResponseGroup.WithInPayments) == ResponseGroup.WithInPayments)
				{
					query = query.Include(x => x.InPayments);
				}
				if ((criteria.ResponseGroup & ResponseGroup.WithShipments) == ResponseGroup.WithShipments)
				{
					query = query.Include(x => x.Shipments);

				    if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems)
				    {
				        query = query.Include(x => x.Shipments.Select(y => y.Items));
				    }

				    if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts)
					{
						query = query.Include(x => x.Shipments.Select(y => y.Discounts));
					}

					if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses)
					{
						query = query.Include(x => x.Shipments.Select(y=>y.Addresses));
					}
				}
			
				retVal = new SearchResult
				{
					TotalCount = query.Count(),
					CustomerOrders = query.OrderByDescending(x => x.CreatedDate)
										  .Skip(criteria.Start)
										  .Take(criteria.Count)
										  .ToArray()
										  .Select(x => x.ToCoreModel(_shippingMethodsService.GetAllShippingMethods(), _paymentMethodsService.GetAllPaymentMethods()))
										  .ToList()
				};
			}
			return retVal;
		}
        public IHttpActionResult Search([ModelBinder(typeof(SearchCriteriaBinder))] coreModel.SearchCriteria criteria)
        {
            var retVal = _searchService.Search(criteria);

            return(Ok(retVal.ToWebModel()));
        }
		public SearchResult Search(SearchCriteria criteria)
		{
			SearchResult retVal = null;
			using (var repository = _orderRepositoryFactory())
			{
				var query = repository.CustomerOrders;
				if (criteria.CustomerId != null)
				{
					query = query.Where(x => x.CustomerId == criteria.CustomerId);
				}
				if (criteria.StoreId != null)
				{
					query = query.Where(x => x.StoreId == criteria.StoreId);
				}

                if (criteria.StartDate != null)
                {
                    query = query.Where(x => x.CreatedDate >= criteria.StartDate);
                }

                if (criteria.EndDate != null)
                {
                    query = query.Where(x => x.CreatedDate <= criteria.EndDate);
                }

				if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts)
				{
					query = query.Include(x => x.Discounts);
				}

				if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses)
				{
					query = query.Include(x => x.Addresses);
				}

				if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems)
				{
					query = query.Include(x => x.Items);

					if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts)
					{
						query = query.Include(x => x.Items.Select(y=>y.Discounts));
					}
				}

				if ((criteria.ResponseGroup & ResponseGroup.WithInPayments) == ResponseGroup.WithInPayments)
				{
					query = query.Include(x => x.InPayments);
				}
				if ((criteria.ResponseGroup & ResponseGroup.WithShipments) == ResponseGroup.WithShipments)
				{
					query = query.Include(x => x.Shipments);

				    if ((criteria.ResponseGroup & ResponseGroup.WithItems) == ResponseGroup.WithItems)
				    {
				        query = query.Include(x => x.Shipments.Select(y => y.Items));
				    }

				    if ((criteria.ResponseGroup & ResponseGroup.WithDiscounts) == ResponseGroup.WithDiscounts)
					{
						query = query.Include(x => x.Shipments.Select(y => y.Discounts));
					}

					if ((criteria.ResponseGroup & ResponseGroup.WithAddresses) == ResponseGroup.WithAddresses)
					{
						query = query.Include(x => x.Shipments.Select(y=>y.Addresses));
					}
				}
			
				retVal = new SearchResult
				{
					TotalCount = query.Count(),
					CustomerOrders = query.OrderByDescending(x => x.CreatedDate)
										  .Skip(criteria.Start)
										  .Take(criteria.Count)
										  .ToArray()
										  .Select(x => x.ToCoreModel())
										  .ToList()
				};
			}
			return retVal;
		}