Пример #1
0
        public OperationResult <IList <StallViewModel> > Recommend([FromUri(Name = "c")] string category, [FromUri(Name = "a")] string area)
        {
            var result    = new OperationResult <IList <StallViewModel> >(true);
            var oriStalls = Models.Stall.GetRecommend(category, area, _db, 20);
            IList <StallViewModel> stalls = new List <StallViewModel>();

            foreach (var s in oriStalls)
            {
                var stallVm = new StallViewModel
                {
                    Id              = s.Id,
                    Name            = s.StallName,
                    InitialProducts = new List <StallProductViewModel>()
                };

                var products = s.SellingProducts.Take(3);
                foreach (var p in products)
                {
                    stallVm.InitialProducts.Add(new StallProductViewModel()
                    {
                        Id   = p.Id,
                        Name = p.BaseName
                    });
                }
                stalls.Add(stallVm);
            }

            result.Data = stalls;

            return(result);
        }
Пример #2
0
        public OperationResult <StallViewModel> Get(int id)
        {
            var result = new OperationResult <StallViewModel>(true);

            //get stall
            StallViewModel stallVM = null;

            Models.Stall stall = null;
            using (var db = new StallEntities())
            {
                stall = Models.Stall.FindById(id, db);
                if (stall == null)
                {
                    result.Succeeded = false;
                    result.Message   = "Can not load products for stall " + id;
                    return(result);
                }

                stallVM = new StallViewModel()
                {
                    Id              = stall.Id,
                    Name            = stall.StallName,
                    Categories      = stall.Categories,
                    ShowCategory    = stall.ShowCategory,
                    InitialProducts = new List <StallProductViewModel>()
                };
            }

            //initial products
            var initProducts = stall.SellingProducts;

            if (stall.ShowCategory)
            {
                //recommend
                initProducts = initProducts.Take(stall.RecommendNumber).ToList();
            }

            foreach (var p in initProducts)
            {
                if (p.Active == true && p.Stock > 0 && p.Price != null)
                {
                    stallVM.InitialProducts.Add(new StallProductViewModel()
                    {
                        Id             = p.Id,
                        Name           = p.BaseName,
                        Image          = p.Image,
                        Price          = p.PriceIncTax,
                        StallId        = p.StallId,
                        StallName      = p.Stall.StallName,
                        Description    = p.Description,
                        Stock          = p.Stock,
                        TrackInventory = p.TrackInventory
                    });
                }
            }

            result.Data = stallVM;
            return(result);
        }
Пример #3
0
        public OperationResult <IList <StallViewModel> > Search([FromUri(Name = "c")] string category, [FromUri(Name = "a")] string area, [FromUri(Name = "k")] string keyword,
                                                                [FromUri(Name = "p")] int page = 0, [FromUri(Name = "ps")] int pageSize = 10)
        {
            var result    = new OperationResult <IList <StallViewModel> >(true);
            var oriStalls = Models.Stall.Search(_db, category, area, keyword, page, pageSize);
            IList <StallViewModel> stalls = new List <StallViewModel>();

            foreach (var s in oriStalls)
            {
                var stallVm = new StallViewModel
                {
                    Id   = s.Id,
                    Name = s.StallName
                };
                stalls.Add(stallVm);
            }

            result.Data = stalls;

            return(result);
        }