Exemplo n.º 1
0
        public PagedResult <ProductInfoDTO> GetProducts(Token token, GetProductsParam getProductsParam, PartialRetrievingInfo retrievingInfo)
        {
            var securityInfo = SecurityManager.EnsureAuthentication(token);
            var service      = new ProductService(Session, securityInfo, Configuration);

            return(service.GetProducts(getProductsParam, retrievingInfo));
        }
Exemplo n.º 2
0
 protected override void BeforeSearch(object param = null)
 {
     criteria = new GetProductsParam();
     if (Customer != null)
     {
         criteria.CustomerId = Customer.GlobalId;
     }
     criteria.PaymentCriteria = SelectedPayment;
     criteria.SortOrder       = SelectedSortOrder;
     criteria.SortAscending   = SortAscending;
     criteria.StartTime       = StartTime;
     criteria.EndTime         = EndTime;
 }
Exemplo n.º 3
0
        public void Payment()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param          = new GetProductsParam();
                var retrievingInfo = new PartialRetrievingInfo();
                var list           = service.GetProducts(data.Token, param, retrievingInfo);
                Assert.IsNotNull(list.Items.Where(x => x.Product.GlobalId == products[1].GlobalId).Single().Payment);
            });
        }
Exemplo n.º 4
0
        public void ForCustomer_AnotherProfile()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param          = new GetProductsParam();
                param.CustomerId   = customers[2].GlobalId;
                var retrievingInfo = new PartialRetrievingInfo();
                service.GetProducts(data.Token, param, retrievingInfo);
            });
        }
Exemplo n.º 5
0
        public void All()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param          = new GetProductsParam();
                var retrievingInfo = new PartialRetrievingInfo();
                var list           = service.GetProducts(data.Token, param, retrievingInfo);
                assert(list, 0, 1, 2);
            });
        }
Exemplo n.º 6
0
        public void Sort_ByName_Desc()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            var         sorted  = products.OrderBy(x => x.Name).Reverse().ToList();

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param           = new GetProductsParam();
                var retrievingInfo  = new PartialRetrievingInfo();
                param.SortOrder     = ProductsSortOrder.ByName;
                param.SortAscending = false;
                var list            = service.GetProducts(data.Token, param, retrievingInfo);
                assertOrder(list, sorted);
            });
        }
Exemplo n.º 7
0
        public void Sort_ByPaid_Asc()
        {
            var         profile = (ProfileDTO)profiles[0].Tag;
            SessionData data    = CreateNewSession(profile, ClientInformation);
            var         sorted  = products.OrderBy(x => x.Payment != null).ToList();

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param           = new GetProductsParam();
                param.SortOrder     = ProductsSortOrder.ByPaid;
                param.SortAscending = true;
                var retrievingInfo  = new PartialRetrievingInfo();
                var list            = service.GetProducts(data.Token, param, retrievingInfo);
                Assert.AreEqual("test2", list.Items[2].Product.Name);
            });
        }
 public PagedResult <ProductInfoDTO> GetProducts(Token token, GetProductsParam getProductsParam, PartialRetrievingInfo retrievingInfo)
 {
     return(exceptionHandling(token, () => InternalService.GetProducts(token, getProductsParam, retrievingInfo)));
 }
Exemplo n.º 9
0
        public PagedResult <ProductInfoDTO> GetProducts(GetProductsParam getProductsParam, PartialRetrievingInfo retrievingInfo)
        {
            Log.WriteWarning("GetProducts:Username={0}", SecurityInfo.SessionData.Profile.UserName);
            if (!SecurityInfo.Licence.IsInstructor)
            {
                throw new LicenceException("This feature is allowed for Instructor account");
            }

            using (var transactionScope = Session.BeginGetTransaction())
            {
                var dbProfile     = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var queryProducts = Session.QueryOver <Product>().Where(x => x.Profile == dbProfile).Fetch(x => x.Payment).Eager;

                if (getProductsParam.StartTime.HasValue)
                {
                    queryProducts = queryProducts.Where(day => day.DateTime >= getProductsParam.StartTime);
                }
                if (getProductsParam.EndTime.HasValue)
                {
                    queryProducts = queryProducts.Where(day => day.DateTime <= getProductsParam.EndTime);
                }
                if (getProductsParam.CustomerId.HasValue)
                {
                    var dbCustomer = Session.Get <Customer>(getProductsParam.CustomerId.Value);
                    if (dbCustomer.Profile != dbProfile)
                    {
                        throw new CrossProfileOperationException("Customer belongs to another user");
                    }
                    queryProducts = queryProducts.Where(day => day.Customer == dbCustomer);
                }
                switch (getProductsParam.PaymentCriteria)
                {
                case PaymentCriteria.WithoutPayment:
                    queryProducts = queryProducts.Where(day => day.Payment == null);
                    break;

                case PaymentCriteria.WithPayment:
                    queryProducts = queryProducts.Where(day => day.Payment != null);
                    break;
                }
                IQueryOverOrderBuilder <Product, Product> orderBuilder;
                switch (getProductsParam.SortOrder)
                {
                case ProductsSortOrder.ByName:
                    orderBuilder = queryProducts.OrderBy(x => x.Name);
                    break;

                case ProductsSortOrder.ByPaid:
                    orderBuilder = queryProducts.OrderBy(x => x.Payment);
                    break;

                default:
                    orderBuilder = queryProducts.OrderBy(x => x.DateTime);
                    break;
                }
                if (getProductsParam.SortAscending)
                {
                    queryProducts = orderBuilder.Asc;
                }
                else
                {
                    queryProducts = orderBuilder.Desc;
                }

                //queryProducts = queryProducts.TransformUsing(Transformers.DistinctRootEntity);
                var listPack = queryProducts.ToPagedResults <ProductInfoDTO, Product>(retrievingInfo);
                transactionScope.Commit();
                return(listPack);
            }
        }