예제 #1
0
        public ListProductViewModel SearchProductList(string srchParam,bool inactive = false)
        {
            ListProductViewModel vm = new ListProductViewModel
            {  Title = "List Products",
                Items = _productRepository.GetAll(inactive).ToList().Where(n => (n.ProductCode.ToLower().StartsWith(srchParam.ToLower()))||(n.Description.ToLower().StartsWith(srchParam.ToLower())) ||  (n.Brand.Name.ToLower().StartsWith(srchParam.ToLower()))
               ).ToList()
                .Select(n => new ListProductViewModel.ListProductViewModelItem
                {
                    Brand = n.Brand.Name,
                    //Flavour=((SaleProduct )n).Flavour==null?"":((SaleProduct )n).Flavour.Name,
                    Flavour = n.GetType() == typeof(SaleProduct) ? ((SaleProduct)n).Flavour == null ? "" : ((SaleProduct)n).Flavour.Name : "",
                    RetProdFalvour = n.GetType() == typeof(ReturnableProduct) ? ((ReturnableProduct)n).Flavour == null ? "" : ((ReturnableProduct)n).Flavour.Name : "",
                    Code = n.ProductCode,
                    Description = n.Description,
                    Packaging = n.Packaging == null ? "" : n.Packaging.Name,
                    VatClassId = n.VATClass == null ? Guid.Empty : n.VATClass.Id,
                    VatClass = n.VATClass == null ? "" : _vatClassRepository.GetById(n.VATClass.Id).VatClass,
                    ProductId = n.Id,


                    isActive = n._Status == EntityStatus.Active ? true : false,


                    ProductType = n.GetType().ToString().Split('.').Last()
                })
                .ToList()
            };
            return vm;
        }
예제 #2
0
 public IList<ListProductViewModel> GetAll(bool inactive = false)
 {
     Stopwatch stopWatch = new Stopwatch();
     stopWatch.Start();            
     ListProductViewModel vm = new ListProductViewModel();
     vm.Title = "List Products";
     var items = _productRepository.GetAll(inactive).Select(s => new ListProductViewModel
     {
             Brand = s.Brand.Name,
             Flavour = s.GetType() == typeof(SaleProduct) ? ((SaleProduct)s).Flavour == null ? "" : ((SaleProduct)s).Flavour.Name : "",
             RetProdFalvour = s.GetType() == typeof(ReturnableProduct) ? ((ReturnableProduct)s).Flavour == null ? "" : ((ReturnableProduct)s).Flavour.Name : "",
             Code = s.ProductCode,
             Description = s.Description,
             PackagingName = s.Packaging == null ? "" : s.Packaging.Name,
             VatClassId = s.VATClass == null ? Guid.Empty : s.VATClass.Id,
             VatClass = s.VATClass == null ? "" : _vatClassRepository.GetById(s.VATClass.Id).VatClass,
             ProductId = s.Id,
             isActive = s._Status == EntityStatus.Active ? true : false,
             ProductTypeName = s.GetType().ToString().Split('.').Last(),
             ProductType = s.GetType() == typeof(SaleProduct) ? ((SaleProduct)s).ProductType == null ? "" : ((SaleProduct)s).ProductType.Name : "",
         }).ToList();
     
     return items;
 }
예제 #3
0
        public IList<ListProductViewModel> GetAll(string searchText, int pageIndex, int pageSize, out int count, bool includeDeactivated = false)
        {
            var vm = new ListProductViewModel();
            vm.Title = "List Products";
            var items = _productRepository.GetAll(searchText, pageIndex, pageSize, out count, includeDeactivated).Select(s => new ListProductViewModel
            {
                Brand = s.Brand.Name,
                Flavour = s.GetType() == typeof(SaleProduct) ? ((SaleProduct)s).Flavour == null ? "" : ((SaleProduct)s).Flavour.Name : "",
                RetProdFalvour = s.GetType() == typeof(ReturnableProduct) ? ((ReturnableProduct)s).Flavour == null ? "" : ((ReturnableProduct)s).Flavour.Name : "",
                Code = s.ProductCode,
                Description = s.Description,
                PackagingName = s.Packaging == null ? "" : s.Packaging.Name,
                VatClassId = s.VATClass == null ? Guid.Empty : s.VATClass.Id,
                VatClass = s.VATClass == null ? "" : _vatClassRepository.GetById(s.VATClass.Id).VatClass,
                ProductId = s.Id,
                isActive = s._Status == EntityStatus.Active ? true : false,
                ProductTypeName = s.GetType().ToString().Split('.').Last(),
                ProductType = s.GetType() == typeof(SaleProduct) ? ((SaleProduct)s).ProductType == null ? "" : ((SaleProduct)s).ProductType.Name : "",
            }).ToList();

            return items;
        }
예제 #4
0
        public ListProductViewModel GetProductList(bool inactive = false)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            //ListProductViewModel vm = new ListProductViewModel();
            //vm.Title = "";
            //var items = _productRepository.GetAll();
            //foreach (var item in items)
            //{
            //    ListProductViewModel.ListProductViewModelItem vit = new ListProductViewModel.ListProductViewModelItem();
            //    if (vit.Brand != null)
            //    {
            //        vit.Brand = item.Brand.Name;
            //        vit.Code = item.ProductCode;
            //        vit.Description = item.Description;
            //        vit.Packaging = item.Packaging.Name;
            //        vit.ProductId = item.Id;
            //        vit.ProductType = item.GetType().ToString().Split('.').Last();
            //        vm.Items.Add(vit);
            //    }

            //}
            ListProductViewModel vm = new ListProductViewModel();
            vm.Title = "List Products";
            foreach (var n in _productRepository.GetAll(inactive))
            {
                vm.Items.Add(new ListProductViewModel.ListProductViewModelItem
                                   {
                                       Brand = n.Brand.Name,
                                       //Flavour=((SaleProduct )n).Flavour==null?"":((SaleProduct )n).Flavour.Name,
                                       Flavour = n.GetType() == typeof(SaleProduct) ? ((SaleProduct)n).Flavour == null ? "" : ((SaleProduct)n).Flavour.Name : "",
                                       RetProdFalvour = n.GetType() == typeof(ReturnableProduct) ? ((ReturnableProduct)n).Flavour == null ? "" : ((ReturnableProduct)n).Flavour.Name : "",
                                       Code = n.ProductCode,
                                       Description = n.Description,
                                       Packaging = n.Packaging == null ? "" : n.Packaging.Name,
                                       VatClassId = n.VATClass == null ? Guid.Empty : n.VATClass.Id,
                                       VatClass = n.VATClass == null ? "" : _vatClassRepository.GetById(n.VATClass.Id).VatClass,
                                       ProductId = n.Id,
                                       isActive = n._Status == EntityStatus.Active ? true : false,
                                       ProductType = n.GetType().ToString().Split('.').Last()
                                   });
            }    

            _log.Debug("Product list" + vm.Brands);
            _log.Debug("Product list" + vm.Packaging);
            _log.Debug("Product list" + vm.Brands);
            _log.Error("Product list" + vm);
            _log.InfoFormat("Product list"+vm);
            stopWatch.Stop();


            TimeSpan ts = stopWatch.Elapsed;


            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10);
            Console.WriteLine("RunTime " + elapsedTime);

            stopWatch.Reset();
            
            _log.InfoFormat("Product View Model Builder\tTime taken to get all products"+elapsedTime);
            
            return vm;                    
        }