public ActionResult PurchaseList(int fMemberId)
        {
            //登入的會員資訊
            CMember Member = (CMember)Session[CMemberSession.Session_Login_User];

            //防止未登入者進入
            if (Member == null)
            {
                return(RedirectToAction("../Member/Login"));
            }

            List <COrder> lsorder = COrderFactory.fn訂單查詢(Member).ToList();
            List <CMemberOrderSelectVM> lsdetailorder = CMemberFactory.fn會員訂單個人查詢(Member).ToList();


            List <CMember> lsmemberseller = new List <CMember>();

            foreach (var item in lsdetailorder)
            {
                CProduct product = new CProduct();
                product = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fTheRemovedDate == null && p.fProductId == item.fProductId);
                if (product == null)
                {
                    break;
                }
                CMember memberseller = new CMember();
                memberseller = CMemberFactory.fn會員查詢().FirstOrDefault(m => m.fMemberId == product.fMemberSellerId);

                lsmemberseller.Add(memberseller);
            }

            //未下架的商品(含商品封面圖片)
            List <CProductPicture> lsproductpic = CProductPictureFactory.fn商品圖片查詢().Where(p => p.fTheRemovedDate == null).DistinctBy(p => p.fProductId).OrderBy(p => p.fProductId).ToList();

            CPurchaseListVM PurchaseListVM = new CPurchaseListVM()
            {
                lsMemberSeller   = lsmemberseller,
                lsProductPicture = lsproductpic,
                lsOrder          = lsorder,
                lsOrderDetail    = lsdetailorder
            };

            return(PartialView("_PurchaseList", PurchaseListVM));
        }
        // GET: ManagerSystem
        public ActionResult HomePage(CMember c)
        {
            CAdmin admin = Session[CAdminSession.Session_Login_User] as CAdmin;

            if (admin == null)
            {
                return(RedirectToAction("../Member/AdminLogin"));
            }
            //資安 未登入時會跳回登入頁面
            int membercount  = CMemberFactory.fn會員查詢().Count();           //統計會員數量
            int memberbrowse = CMemberBrowseFactory.fn會員瀏覽紀錄查詢().Count(); //統計總瀏覽量
            int totalprice   = COrderFactory.fn訂單總金額();                   //統計金額交易量
            int totalorder   = COrderFactory.fn訂單商品累積量();                 //總訂單數量

            ViewBag.totalprice  = totalprice.ToString("c0");
            ViewBag.browse      = memberbrowse.ToString();
            ViewBag.membercount = membercount.ToString();
            ViewBag.totalorder  = totalorder;

            List <CProduct> lsproduct = CProductFactory.fn商品查詢().ToList();//撈出產品列表
            List <CProductAndProductCompareViewModel> lsProductAndProductCompareVM = new List <CProductAndProductCompareViewModel>();
            //產品與他的產品分類空列表
            List <CProductCompare> lsproductcategory = new List <CProductCompare>();//產品分類空列表

            foreach (var p in lsproduct)
            {
                List <CProductCompare> vlsProductcategory = CProductCompareFactory.fn商品類別對照查詢()
                                                            .Where(m => m.fProductId == p.fProductId)
                                                            .ToList();//抓出某產品所有產品分類
                lsProductAndProductCompareVM.Add(new CProductAndProductCompareViewModel()
                {
                    product          = p,                 //單一產品
                    lsProductCompare = vlsProductcategory //上述單一產品的多項標籤
                });
            }
            CShoppingDataViewModel sd = new CShoppingDataViewModel()
            {
                lsMember  = CMemberFactory.fn會員查詢().ToList(),
                ls產品與產品分類 = lsProductAndProductCompareVM
            };//將資訊加入列表

            return(View("HomePage", "_LayoutAdmin", sd));
        }
        public ActionResult MyMoney(int fMemberId)
        {
            //登入的會員資訊
            CMember Member = (CMember)Session[CMemberSession.Session_Login_User];

            //防止未登入者進入
            if (Member == null)
            {
                return(RedirectToAction("../Member/Login"));
            }
            List <CIncome>      lsincome      = CIncomeFactory.fn公司收入查詢().Where(i => (i.fMemberId == Member.fMemberId && i.fIncomeCategory == "儲值") || (i.fMemberId == Member.fMemberId && i.fIncomeCategory == "獲利")).ToList();
            List <COrder>       lsorder       = COrderFactory.fn訂單查詢(Member).ToList();
            List <CDetailOrder> lsdetailorder = CDetailOrderFactory.fn訂單明細查詢().ToList();

            CMoneyVM MoneyVM = new CMoneyVM()
            {
                lsIncome      = lsincome,
                lsOrder       = lsorder,
                lsOrderDetail = lsdetailorder
            };

            return(PartialView("_MyMoney", MoneyVM));
        }
        public void ToOrder(int totalprice, int remain, int cartId)
        {
            CMember member = (CMember)Session[CMemberSession.Session_Login_User];//會員
            COrder  o      = new COrder();

            o.fPurchaseDate = DateTime.UtcNow.AddHours(08);
            o.fTotalPrice   = totalprice;
            o.fMemberId     = member.fMemberId;
            COrderFactory.fn訂單新增(o);

            CMemberFactory.fn會員更新點數(member, remain);

            CNotice c = new CNotice();

            c.fCategoryType   = "系統";
            c.fLink           = "超連結";
            c.fNoticeDatetime = DateTime.UtcNow.AddHours(08);
            c.fMemberId       = member.fMemberId;
            c.fNoticeContent  = "您的訂單已完成了";
            CNoticeFactory.fn通知訂單訊息新增(c);

            List <CCartProduct> CP = CCartProductFactory.fn購物車商品個人查詢(cartId).ToList();

            var f = CNoteFolderFactory.fn筆記資料夾查詢(member).Where(q => q.fFolderName == "未分類筆記").ToList();

            int orderid = COrderFactory.fn訂單查詢(member).LastOrDefault().fOrderId;

            foreach (var a in CP)
            {
                CDetailOrderFactory.fn訂單明細新增(orderid, a.fProductId);
                CNotice c1 = new CNotice();
                c1.fCategoryType   = "銷售";
                c1.fLink           = "超連結";
                c1.fNoticeDatetime = DateTime.UtcNow.AddHours(08);
                c1.fMemberId       = a.fMemberSellerId;
                c1.fNoticeContent  = "您的" + a.fName + "已被購買";
                CNoticeFactory.fn通知訂單訊息新增(c1);

                CIncome i1 = new CIncome();
                i1.fIncome          = a.fPrice;
                i1.fPaymentDateTime = DateTime.UtcNow.AddHours(08);
                i1.fIncomeCategory  = "獲利";
                i1.fMemberId        = a.fMemberSellerId;
                CIncomeFactory.fn公司獲利新增(i1);

                var     point  = CMemberFactory.fn會員查詢().Where(z => z.fMemberId == a.fMemberSellerId);
                int     point1 = (point.Single().fMoneyPoint) + a.fPrice;
                CMember cm1    = new CMember();
                cm1.fMemberId = point.Single().fMemberId;
                CMemberFactory.fn會員更新點數(cm1, point1);

                var t = CNoteFactory.fn私人筆記全部查詢().Where(q => q.fFolderId == f.Single().fFolderId).ToList();

                int t1 = t.Count();

                CNote n = new CNote();
                n.fNoteListName     = a.fName;
                n.fCreateDateTime   = DateTime.UtcNow.AddHours(08);
                n.fEditDateTime     = DateTime.UtcNow.AddHours(08);
                n.fNoteListLevel    = t1;
                n.fIsMyFavourite    = false;
                n.fIsTrash          = false;
                n.fFolderId         = f.Single().fFolderId;
                n.fJsonContent      = a.fContent;
                n.fTheShareLink     = null;
                n.fTheContactPerson = null;
                n.fHTMLContent      = "";
                CNoteFactory.fn訂單私人筆記新增(n);
            }

            CCartFactory.fn購物車個人更新(cartId);
        }