public List <CarCarPlanViewModel> SearchCategory(string searchString)
        {
            List <CarCarPlanViewModel> CarCarPlanItems = new List <CarCarPlanViewModel>();
            var result = _prContext.Projects.Where(x => x.ProjectStatus == "結束且成功").ToList();

            foreach (var item in result)
            {
                var trueprojectPlan = _prContext.Plans.Where(x => x.ProjectId == item.ProjectId && x.AddCarCarPlan == true && x.Project.Category.Contains(searchString)).ToList();

                if (trueprojectPlan != null)
                {
                    foreach (var trueItem in trueprojectPlan)
                    {
                        CarCarPlanViewModel cv = new CarCarPlanViewModel()
                        {
                            PlanImgUrl      = trueItem.PlanImgUrl,
                            ProjectName     = trueItem.ProjectName,
                            Category        = trueItem.Project.Category,
                            PlanTitle       = trueItem.PlanTitle,
                            CreatorName     = trueItem.Project.CreatorName,
                            PlanPrice       = (int)trueItem.PlanPrice,
                            PlanId          = trueItem.PlanId,
                            PlanDescription = trueItem.PlanDescription,
                            QuantityLimit   = trueItem.QuantityLimit,
                            AddCarCarPlan   = trueItem.AddCarCarPlan,
                        };
                        CarCarPlanItems.Add(cv);
                    }
                }
            }
            return(CarCarPlanItems);
        }
        public int AddtoCart(CarCarPlanViewModel carcarPlanVM)
        {
            var cartList = new CartItemListViewModel
            {
                CartItems = new List <CarCarPlanViewModel>()
            };

            ///若購物車為空,則初始化購物車,並放入Session["Cart"]
            if (Session["Cart"] == null)
            {
                var cart = _CartService.CreateANewCart(carcarPlanVM);
                cartList.CartItems.Add(cart);
                Session["Cart"] = cartList;
            }
            ///若購物車不為空,則購物車新增CarCarPlanViewModel
            else
            {
                cartList = (CartItemListViewModel)Session["Cart"];
                var cartFiilter = _CartService.CheckId(cartList, carcarPlanVM);

                Session["Cart"] = cartFiilter;
            }

            ///前端畫面顯示購物車內購物項目的數量。若有重複,則不重複計算
            return(cartList.CartItems.Count);
        }
Esempio n. 3
0
        /// <summary>
        /// 查看購物車內是否有重複方案:若有,則方案數量+1;若無,購物車新增一筆方案
        /// </summary>
        /// <param name="cartItems"></param>
        /// <param name="carcarPlanVM"></param>
        /// <returns></returns>
        public CartItemListViewModel CheckId(CartItemListViewModel cartItems, CarCarPlanViewModel carcarPlanVM)
        {
            var result = cartItems.CartItems.Where(x => x.PlanId == carcarPlanVM.PlanId).Select(x => x).FirstOrDefault();

            ///若沒有找到相同項目,則新增一個項目
            if (result == default(CarCarPlanViewModel))
            {
                var cart = new CarCarPlanViewModel
                {
                    CartId        = cartItems.CartItems.Count() + 1,
                    PlanId        = carcarPlanVM.PlanId,
                    PlanTitle     = carcarPlanVM.PlanTitle,
                    PlanImgUrl    = carcarPlanVM.PlanImgUrl,
                    PlanPrice     = carcarPlanVM.PlanPrice,
                    Quantity      = carcarPlanVM.Quantity,
                    QuantityLimit = carcarPlanVM.QuantityLimit,
                    ProjectId     = carcarPlanVM.ProjectId
                };
                cartItems.CartItems.Add(cart);
                return(cartItems);
            }
            //若有找到相同項目,則該項目數量+1
            else
            {
                result.Quantity += 1;
                return(cartItems);
            }
        }
Esempio n. 4
0
        public PayViewModel QueryByPlanId(CartItemListViewModel cart) //撈資料庫資料 用購物車的planId找到資料庫的planId
        {
            var session       = HttpContext.Current.Session;
            var memberSession = ((MemberViewModel)session["Member"]);
            var member        = _repository.GetAll <Member>().FirstOrDefault(x => x.MemberId == memberSession.MemberId);

            var viewmodel = new PayViewModel
            {
                MemberName     = member.MemberName,
                MemberAddress  = member.MemberAddress,
                MemberPhone    = member.MemberPhone,
                MemberConEmail = member.MemberRegEmail,
                MemberId       = member.MemberId,
                CartItems      = new List <CarCarPlanViewModel>() //先給他一個空的集合 讓viewmodel知道我需要這筆資料
            };

            foreach (var item in cart.CartItems)                                                     //先撈session
            {
                var plan = _repository.GetAll <Plan>().FirstOrDefault(X => X.PlanId == item.PlanId); //資料庫id==sessionId 之後要移出foreach

                var CartItem = new CarCarPlanViewModel
                {
                    PlanId     = plan.PlanId,
                    Quantity   = item.Quantity,
                    PlanPrice  = plan.PlanPrice,
                    PlanImgUrl = plan.PlanImgUrl,
                    PlanTitle  = plan.PlanTitle,
                    ProjectId  = plan.ProjectId,
                };
                viewmodel.CartItems.Add(CartItem);
            }
            return(viewmodel);
        }
Esempio n. 5
0
        //重新購買 pay頁面
        public PayViewModel Reshop(PayViewModel cart) //撈資料庫資料 用backingRecordviewmodel的planId找到資料庫的planId
        {
            var session       = HttpContext.Current.Session;
            var memberSession = ((MemberViewModel)session["Member"]);
            var member        = _repository.GetAll <Member>().FirstOrDefault(x => x.MemberId == memberSession.MemberId);

            var viewmodel = new PayViewModel
            {
                MemberName     = member.MemberName,
                MemberAddress  = member.MemberAddress,
                MemberPhone    = member.MemberPhone,
                MemberConEmail = member.MemberRegEmail,
                MemberId       = member.MemberId,
                CartItems      = new List <CarCarPlanViewModel>() //先給他一個空的集合 讓viewmodel知道我需要這筆資料
            };
            var myOrder       = _repository.GetAll <Order>().FirstOrDefault(x => x.OrderId == cart.OrderId);
            var myOrderDetail = _repository.GetAll <OrderDetail>().Where(x => x.OrderId == myOrder.OrderId).Select(x => x).ToList();

            foreach (var item in myOrderDetail)
            {
                var CartItem = new CarCarPlanViewModel
                {
                    PlanId     = item.PlanId,
                    Quantity   = item.OrderQuantity,
                    PlanPrice  = item.OrderPrice,
                    PlanImgUrl = item.OrderPlanImgUrl,
                    PlanTitle  = item.PlanTitle,
                    ProjectId  = item.ProjectId,
                };
                viewmodel.CartItems.Add(CartItem);
            }
            return(viewmodel);
        }
        //條件
        public List <CarCarPlanViewModel> GetOtherPlan(Expression <Func <Plan, bool> > Category)
        {
            //List<CarCarPlanViewModel> CarCarPlanItems = new List<CarCarPlanViewModel>();
            //var result = _prContext.Projects.Where(x => x.ProjectStatus == "結束且成功").ToList();

            //foreach (var item in result)
            //{
            //    var trueprojectPlan = _prContext.Plans.Where(x => x.ProjectId == item.ProjectId && x.AddCarCarPlan == true).ToList();

            //    if (trueprojectPlan != null)
            //    {
            //        foreach (var trueItem in trueprojectPlan)
            //        {
            //            CarCarPlanViewModel cv = new CarCarPlanViewModel()
            //            {
            //                PlanImgUrl = trueItem.PlanImgUrl,
            //                ProjectName = trueItem.ProjectName,
            //                Category = trueItem.Project.Category,
            //                PlanTitle = trueItem.PlanTitle,
            //                CreatorName = trueItem.Project.CreatorName,
            //                PlanPrice = (int)trueItem.PlanPrice,
            //                PlanId = trueItem.PlanId,
            //                PlanDescription = trueItem.PlanDescription,
            //                QuantityLimit = trueItem.QuantityLimit,
            //                AddCarCarPlan = trueItem.AddCarCarPlan,

            //            };
            //            CarCarPlanItems.Add(cv);
            //        }
            //    }
            //}
            //return CarCarPlanItems;

            List <CarCarPlanViewModel> lccpvm = new List <CarCarPlanViewModel>();

            var carcarPlans = _repository.GetAll <Plan>().Where(Category);

            foreach (var item in carcarPlans.ToList())
            {
                var cv = new CarCarPlanViewModel()
                {
                    PlanImgUrl      = item.PlanImgUrl,
                    ProjectName     = item.ProjectName,
                    Category        = item.Project.Category,
                    PlanTitle       = item.PlanTitle,
                    CreatorName     = item.Project.CreatorName,
                    PlanPrice       = (int)item.PlanPrice,
                    PlanId          = item.PlanId,
                    PlanDescription = item.PlanDescription,
                    QuantityLimit   = item.QuantityLimit,
                    AddCarCarPlan   = item.AddCarCarPlan
                };
                lccpvm.Add(cv);
            }

            return(lccpvm);
        }
        public ActionResult RemoveCartItem(CarCarPlanViewModel carcarPlanVM)
        {
            //還原Session
            var carList = (CartItemListViewModel)Session["Cart"];

            carList = _CartService.DeleteId(carList, carcarPlanVM);

            Session["Cart"] = carList;


            return(View("ListShoppingCart"));
        }
Esempio n. 8
0
        /// <summary>
        /// 此方法為刪除購物車內某一商品:cartItems為目前購物車內容,carcarPlanVM則為欲刪除項目
        /// </summary>
        /// <param name="cartItems"></param>
        /// <param name="carcarPlanVM"></param>
        /// <returns></returns>
        public CartItemListViewModel DeleteId(CartItemListViewModel cartItems, CarCarPlanViewModel carcarPlanVM)
        {
            var result = cartItems.CartItems.Where(x => x.PlanId == carcarPlanVM.PlanId).Select(x => x).FirstOrDefault();

            if (result == default(CarCarPlanViewModel))
            {
            }
            else
            {
                cartItems.CartItems.Remove(result);
            }
            return(cartItems);
        }
Esempio n. 9
0
        /// <summary>
        /// 購物車新增一筆方案
        /// </summary>
        /// <param name="CarCarPlanVM"></param>
        /// <returns></returns>
        public CarCarPlanViewModel CreateANewCart(CarCarPlanViewModel CarCarPlanVM)
        {
            var cart = new CarCarPlanViewModel
            {
                CartId        = 1,
                PlanId        = CarCarPlanVM.PlanId,
                PlanTitle     = CarCarPlanVM.PlanTitle,
                PlanImgUrl    = CarCarPlanVM.PlanImgUrl,
                PlanPrice     = CarCarPlanVM.PlanPrice,
                Quantity      = CarCarPlanVM.Quantity,
                QuantityLimit = CarCarPlanVM.QuantityLimit,
                ProjectId     = CarCarPlanVM.ProjectId
            };

            return(cart);
        }
Esempio n. 10
0
        public CarCarPlanViewModel QueryByPlanId(int Id)
        {
            var plan = repository.GetAll <Plan>().FirstOrDefault(X => X.PlanId == Id);


            if (plan == null)
            {
                return(new CarCarPlanViewModel());
            }

            var cartItem = new CarCarPlanViewModel
            {
                PlanId     = plan.PlanId,
                PlanTitle  = plan.PlanTitle,
                PlanPrice  = plan.PlanPrice,
                PlanImgUrl = plan.PlanImgUrl,
                Quantity   = 1
            };

            return(cartItem);
        }
        public CarCarPlanViewModel GetCarCarPlan(Expression <Func <Plan, bool> > PlanId)
        {
            //List<CarCarPlanViewModel> lcpvm = new List<CarCarPlanViewModel>();

            var planCard = _repository.GetAll <Plan>().FirstOrDefault(PlanId);

            CarCarPlanViewModel cv = new CarCarPlanViewModel()
            {
                PlanId          = planCard.PlanId,
                PlanImgUrl      = planCard.PlanImgUrl,
                Category        = planCard.Project.Category,
                ProjectName     = planCard.ProjectName,
                PlanTitle       = planCard.PlanTitle,
                PlanDescription = planCard.PlanDescription,
                PlanPrice       = (int)planCard.PlanPrice,
                CreatorName     = planCard.Project.CreatorName,
                QuantityLimit   = planCard.QuantityLimit,
                AddCarCarPlan   = planCard.AddCarCarPlan
            };

            return(cv);
        }
Esempio n. 12
0
        //搜尋 plan
        public HomeViewModel GetSearchCardPlan(Expression <Func <Plan, bool> > Keyselector)
        {
            var result = _repository.GetAll <Plan>().Where(Keyselector).ToList();

            HomeViewModel homeviewmodel = new HomeViewModel()
            {
                ProjectItem = new ProjectListViewModel()
                {
                    ProjectItems = new List <ProjectViewModel>()
                },

                CarCarPlanItem = new CarCarPlanListViewModel()
                {
                    CarCarPlanItems = new List <CarCarPlanViewModel>()
                }
            };

            foreach (var item in result)
            {
                var planbox = new CarCarPlanViewModel()
                {
                    PlanImgUrl      = item.PlanImgUrl,
                    ProjectName     = item.ProjectName,
                    Category        = item.Project.Category,
                    PlanTitle       = item.PlanTitle,
                    CreatorName     = item.Project.CreatorName,
                    PlanPrice       = (int)item.PlanPrice,
                    PlanId          = item.PlanId,
                    PlanDescription = item.PlanDescription,
                    QuantityLimit   = item.QuantityLimit,
                    AddCarCarPlan   = item.AddCarCarPlan
                };
                if (planbox.QuantityLimit > 0)
                {
                    homeviewmodel.CarCarPlanItem.CarCarPlanItems.Add(planbox);
                }
            }
            return(homeviewmodel);
        }
        //全部
        public List <CarCarPlanViewModel> GetAllTotal()
        {
            List <CarCarPlanViewModel> CarCarPlanItems = new List <CarCarPlanViewModel>();

            foreach (var item in _repository.GetAll <Plan>().ToList())
            {
                CarCarPlanViewModel cv = new CarCarPlanViewModel()
                {
                    PlanImgUrl      = item.PlanImgUrl,
                    ProjectName     = item.ProjectName,
                    Category        = item.Project.Category,
                    PlanTitle       = item.PlanTitle,
                    CreatorName     = item.Project.CreatorName,
                    PlanPrice       = (int)item.PlanPrice,
                    PlanId          = item.PlanId,
                    PlanDescription = item.PlanDescription,
                    QuantityLimit   = item.QuantityLimit,
                    AddCarCarPlan   = item.AddCarCarPlan
                };
                CarCarPlanItems.Add(cv);
            }
            return(CarCarPlanItems);
        }
Esempio n. 14
0
        public HomeViewModel GetAllTotal()
        {
            HomeViewModel homeviewmodel = new HomeViewModel()
            {
                ProjectItem = new ProjectListViewModel()
                {
                    ProjectItems = new List <ProjectViewModel>()
                },

                CarCarPlanItem = new CarCarPlanListViewModel()
                {
                    CarCarPlanItems = new List <CarCarPlanViewModel>()
                }
            };

            foreach (var item in _repository.GetAll <Project>().ToList())
            {
                //UpdateProjectStatus(item);
                ProjectViewModel pv = new ProjectViewModel()
                {
                    ProjectMainUrl  = item.ProjectMainUrl,
                    Category        = item.Category,
                    ProjectStatus   = item.ProjectStatus,
                    ProjectName     = item.ProjectName,
                    CreatorName     = item.CreatorName,
                    FundingAmount   = (int)item.FundingAmount,
                    AmountThreshold = item.AmountThreshold,
                    EndDate         = item.EndDate,
                    StartDate       = item.StartDate,
                    ProjectId       = item.ProjectId,
                    ApprovingStatus = item.ApprovingStatus,
                    Fundedpeople    = item.Fundedpeople,
                };
                homeviewmodel.ProjectItem.ProjectItems.Add(pv);
            }


            //List<CarCarPlanViewModel> CarCarPlanItems = new List<CarCarPlanViewModel>();
            var result = _prContext.Projects.Where(x => x.ProjectStatus == "結束且成功").ToList();

            foreach (var item in result)
            {
                var trueprojectPlan = _prContext.Plans.Where(x => x.ProjectId == item.ProjectId && x.AddCarCarPlan == true).ToList();

                if (trueprojectPlan != null)
                {
                    foreach (var trueItem in trueprojectPlan)
                    {
                        CarCarPlanViewModel cv = new CarCarPlanViewModel()
                        {
                            PlanImgUrl      = trueItem.PlanImgUrl,
                            ProjectName     = trueItem.ProjectName,
                            Category        = trueItem.Project.Category,
                            PlanTitle       = trueItem.PlanTitle,
                            CreatorName     = trueItem.Project.CreatorName,
                            PlanPrice       = (int)trueItem.PlanPrice,
                            PlanId          = trueItem.PlanId,
                            PlanDescription = trueItem.PlanDescription,
                            QuantityLimit   = trueItem.QuantityLimit,
                            AddCarCarPlan   = trueItem.AddCarCarPlan,
                        };
                        if (cv.QuantityLimit > 0)
                        {
                            homeviewmodel.CarCarPlanItem.CarCarPlanItems.Add(cv);
                        }
                    }
                }
            }



            //foreach (var item in _repository.GetAll<Plan>())
            //{

            //    CarCarPlanViewModel cv = new CarCarPlanViewModel()
            //    {
            //        PlanImgUrl = item.PlanImgUrl,
            //        ProjectName = item.ProjectName,
            //        Category = item.Project.Category,
            //        PlanTitle = item.PlanTitle,
            //        CreatorName = item.Project.CreatorName,
            //        PlanPrice = (int)item.PlanPrice,
            //        PlanId = item.PlanId,
            //        PlanDescription = item.PlanDescription,
            //        ProjectId = item.ProjectId,
            //        QuantityLimit = item.QuantityLimit,
            //        AddCarCarPlan = item.AddCarCarPlan
            //    };
            //    if (cv.QuantityLimit > 0)
            //    {
            //        homeviewmodel.CarCarPlanItem.CarCarPlanItems.Add(cv);
            //    }
            //}

            return(homeviewmodel);
        }