public ActionResult Productblock(int ProductId) { if (Session[CMemberSession.Session_Login_User] == null) { return(RedirectToAction("../Member/Login")); } CMember member = (CMember)Session[CMemberSession.Session_Login_User]; CProductPicture myProductPicture = CProductPictureFactory.fn商品圖片查詢().FirstOrDefault(n => n.fProductId == ProductId); //CProduct myProduct = CProductFactory.fn商品查詢().FirstOrDefault(n => n.fProductId == ProductId); return(PartialView("_Productblock", myProductPicture)); }
public ActionResult CreateProduct(CShoppingAccountCenterVM NewProduct, int?[] fCategoryId, string[] ProductPicture) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //防止未登入者進入 if (member == null) { return(RedirectToAction("../Member/Login")); } //商品新增 CProduct product = new CProduct(); product.fName = NewProduct.Product.fName; product.fDescription = NewProduct.Product.fDescription; product.fContent = NewProduct.Content; //抓JSON資料 product.fPrice = NewProduct.Product.fPrice; product.fLaunchDate = DateTime.UtcNow.AddHours(08); product.fTheRemovedDate = null; product.fDownloadTimes = 0; product.fLikeCount = 0; product.fMemberSellerId = member.fMemberId; product = CProductFactory.fn商品新增(member, product); //商品圖片新增 CProductPicture productPicture = new CProductPicture(); //如果沒有選就給預設圖片(封面) if (ProductPicture[0] == "") { productPicture.fPicture = "https://creazilla-store.fra1.digitaloceanspaces.com/emojis/44574/notebook-emoji-clipart-md.png";//預設的圖片 productPicture.fProductId = product.fProductId; CProductPictureFactory.fn商品圖片新增(product, productPicture); } else { foreach (var item in ProductPicture) { if (item != "") { productPicture.fPicture = item; productPicture.fProductId = product.fProductId; CProductPictureFactory.fn商品圖片新增(product, productPicture); } } } //商品類別新增 CProductCompare productCompare = new CProductCompare(); if (fCategoryId == null) { } else { foreach (var item in fCategoryId) { CProductCategory productCategory = CProductCategoryFactory.fn商品類別查詢().Where(c => c.fCategoryId == item).FirstOrDefault(); productCompare.fProductId = product.fProductId; productCompare.fCategoryId = item.Value; CProductCompareFactory.fn商品類別對照新增(product, productCategory); } } return(Redirect("../ShoppingAccountCenter?goto=seller")); }
// GET: AllProduct public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //防止未登入者進入 if (member == null) { return(RedirectToAction("../Member/Login")); } //排序條件(日期/價格/下載量/讚數) ViewBag.CurrentSort = sortOrder; ViewBag.DateSortParm = String.IsNullOrEmpty(sortOrder) ? "Date" : ""; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; //記錄每頁商品數及目前頁數 int pageSize = 8; int pageNumber = (page ?? 1); //未下架的商品(含商品封面圖片) List <CProductPicture> lsproduct = CProductPictureFactory.fn商品圖片查詢().Where(p => p.fTheRemovedDate == null).DistinctBy(p => p.fProductId).OrderBy(p => p.fProductId).ToList(); //篩選商品(類別/名稱/描述) switch (searchString) { case "Education": List <CProductCompare> lscategory = CProductCompareFactory.fn商品類別對照查詢().Where(c => c.fCategoryName == "程式").ToList(); List <CProductPicture> lsproducttag1 = new List <CProductPicture>(); foreach (var item in lscategory) { CProductPicture producttag1 = new CProductPicture(); producttag1 = lsproduct.Where(p => p.fProductId == item.fProductId && p.fTheRemovedDate == null).FirstOrDefault(); if (producttag1 != null) { lsproducttag1.Add(producttag1); } } lsproduct = lsproducttag1; break; case null: searchString = currentFilter; break; default: lsproduct = lsproduct.Where(p => p.fName.Contains(searchString) || p.fDescription.Contains(searchString)).ToList(); break; } switch (sortOrder) { case "New": lsproduct = lsproduct.Where(p => DateTime.UtcNow.AddHours(08).AddMonths(-1).Month < p.fLaunchDate.Month && p.fLaunchDate.Month <= DateTime.UtcNow.AddHours(08).Month).OrderByDescending(p => p.fLaunchDate).ToList(); break; case "Date": lsproduct = lsproduct.OrderBy(p => p.fLaunchDate).ToList(); break; case "Price": lsproduct = lsproduct.OrderBy(p => p.fPrice).ToList(); break; case "Price_desc": lsproduct = lsproduct.OrderByDescending(p => p.fPrice).ToList(); break; case "DownLoad_desc": lsproduct = lsproduct.OrderByDescending(p => p.fDownloadTimes).ToList(); break; case "Like_desc": lsproduct = lsproduct.OrderByDescending(p => p.fLikeCount).ToList(); break; case "Free": lsproduct = lsproduct.Where(p => p.fPrice == 0).ToList(); break; default: lsproduct = lsproduct.OrderByDescending(p => p.fLaunchDate).ToList(); break; } //裝多個CShoppingHomeVM的容器 List <CShoppingHomeVM> lsshoppinghomeVM = new List <CShoppingHomeVM>(); foreach (var product in lsproduct) { //撈出該商品的賣家資訊 CMember memberseller = CMemberFactory.fn會員查詢().FirstOrDefault(m => m.fMemberId == product.fMemberSellerId); //撈出該商品的類別 List <CProductCompare> category = CProductCompareFactory.fn商品類別對照查詢().Where(c => c.fProductId == product.fProductId).ToList(); //CShoppingHomeVM內的變數給值 CShoppingHomeVM shoppinghomeVM = new CShoppingHomeVM() { member = memberseller, lsproductcategory = category, productpicture = product, }; lsshoppinghomeVM.Add(shoppinghomeVM); } IPagedList <CShoppingHomeVM> pagedlist = lsshoppinghomeVM.ToPagedList(pageNumber, pageSize); return(View("Index", pagedlist)); }