public ActionResult Create(DetailedProductViewModel viewDP) { string storeLoc = TempData.Peek("adminLoc").ToString(); try { if (!ModelState.IsValid) { ModelState.AddModelError("", "Invalid input format"); return(View()); } // avoid duplicate var foundProduct = _storeRepo.GetOneProductByNameAndCategory(viewDP.Name, viewDP.Category); if (foundProduct != null) { ModelState.AddModelError("", "This product already exist in this category"); return(View()); } // a new randomly generated id for a new product string productID = Guid.NewGuid().ToString().Substring(0, 10); var cProduct = new CProduct(productID, viewDP.Name, viewDP.Category, viewDP.Price, viewDP.Quantity); _storeRepo.StoreAddOneProduct(storeLoc, cProduct, viewDP.Quantity); return(RedirectToAction(nameof(Index))); } catch (Exception e) { _logger.LogError(e, "error while tring to add a product"); ModelState.AddModelError("", "failed to create a product"); return(View()); } }
// order level public COrder GetAnOrderByID(string orderid) { using var context = new Project0databaseContext(_contextOptions); Orderr dbOrder = context.Orderrs .Include(x => x.Orderproducts) .ThenInclude(x => x.Product) .FirstOrDefault(x => x.Orderid == orderid); Orderr dbCustomer = context.Orderrs.Include(x => x.Customer).FirstOrDefault(x => x.Orderid == orderid); if (dbOrder == null) { return(null); } if (dbCustomer == null) { return(null); } COrder order = new COrder(orderid, new CStore(dbOrder.Storeloc), new CCustomer(dbCustomer.Customer.Firstname, dbCustomer.Customer.Lastname, dbCustomer.Customer.Phonenumber), dbOrder.Orderedtime, dbOrder.Totalcost); foreach (var product in dbOrder.Orderproducts) { CProduct p = new CProduct(product.Product.Productid, product.Product.Name, product.Product.Category, product.Product.Price, product.Quantity); order.ProductList.Add(p); } return(order); }
protected void btnAdd_Click(object sender, EventArgs e) { CProduct cp = new CProduct() { Name = txtName.Text, Brand = DList1.Text, Category = txtCate.Text, Modal = DList2.Text, Stock = txtStock.Text, Price = int.Parse(txtPrice.Text), Description = txtDesc.Text, Passengers = DList3.Text }; if (FileUpload1.HasFile) { foreach (var postedFile in FileUpload1.PostedFiles) { string fileName = Path.GetFileName(postedFile.FileName); postedFile.SaveAs(Server.MapPath("~/FileImage/") + fileName); } //filName } }
public override void DoSelfDuty() { CRes cRes = this.mediator.GetCRes(); CProduct cProduct = ProcessC(cRes); this.mediator.OutputCProduct(cProduct); }
// GET: Product/Edit/5 public ActionResult Edit(int id) { CProduct product = new CProduct(); DataTable dtb = new DataTable(); using (SqlConnection con = new SqlConnection(connectionStrings)) { con.Open(); string query = "SELECT * FROM tProduct Where fProductId = @fProductId"; SqlDataAdapter adapter = new SqlDataAdapter(query, con); adapter.SelectCommand.Parameters.AddWithValue("@fProductId", id); adapter.Fill(dtb); } if (dtb.Rows.Count == 1) { product.fProductId = Convert.ToInt32(dtb.Rows[0][0].ToString()); product.fProductName = dtb.Rows[0][1].ToString(); product.fPrice = Convert.ToDecimal(dtb.Rows[0][2].ToString()); product.fCount = Convert.ToInt32(dtb.Rows[0][3].ToString()); return(View(product)); } else { return(RedirectToAction("Index")); } }
public ActionResult EditProduct(CShoppingAccountCenterVM NewProduct, int[] fCategoryId, int?fProductId) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //防止未登入者進入 if (member == null) { return(RedirectToAction("../Member/Login")); } CProduct product = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == fProductId); product.fName = NewProduct.Product.fName; product.fDescription = NewProduct.Product.fDescription; product.fContent = NewProduct.Content; product.fPrice = NewProduct.Product.fPrice; product.fLaunchDate = DateTime.UtcNow.AddHours(08); product.fTheRemovedDate = null; product.fDownloadTimes = 0; product.fLikeCount = 0; product.fMemberSellerId = member.fMemberId; CProductFactory.fn商品更新(product); return(RedirectToAction("Index")); }
}// not mapped public List <CProduct> GetInventoryOfOneStoreByCategory(string storeLoc, string category) { using var context = new Project0databaseContext(_contextOptions); var dbStore = context.Stores.Include(x => x.Inventories) .ThenInclude(x => x.Product) .FirstOrDefault(x => x.Storeloc == storeLoc); if (dbStore == null) { return(null); } // need linq List <CProduct> inventory = new List <CProduct>(); CProduct p = new CProduct(); foreach (var product in dbStore.Inventories) { if (product.Product.Category == category) { p = new CProduct(product.Product.Productid, product.Product.Name, product.Product.Category, product.Product.Price, product.Quantity); inventory.Add(p); } } return(inventory); }// not mapped
// GET: ProductDetail public ActionResult ProductDetail(int ProductId) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //防止未登入者進入 if (member == null) { return(RedirectToAction("../Member/Login")); } //所有會員資訊 List <CMember> lsMember = CMemberFactory.fn會員查詢().ToList(); List <CMember> Isbanned = CMemberFactory.fn會員查詢().Where(n => n.fMemberId == member.fMemberId).ToList(); //所選到的商品 CProduct product = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == ProductId); //該商品的賣家資訊 CMember memberseller = CMemberFactory.fn會員查詢().FirstOrDefault(m => m.fMemberId == product.fMemberSellerId); //該商品的圖片(多個) List <CProductPicture> lsProductPicture = CProductPictureFactory.fn商品圖片查詢().Where(p => p.fProductId == ProductId).ToList(); //該商品的類別(多個) List <CProductCompare> lsCategory = CProductCompareFactory.fn商品類別對照查詢().Where(c => c.fProductId == ProductId).ToList(); //該商品的留言(多個) List <CComment> lsProductComment = CCommentFactory.fn留言查詢().Where(c => c.fProductId == ProductId).ToList(); List <CProductRank> lsProductRank = CProductRankFactory.fn評價查詢(ProductId).ToList(); //新增瀏覽紀錄 CProductBrowse productBrowse = new CProductBrowse() { fBrowseDataTime = DateTime.UtcNow.AddHours(08), fProductId = ProductId }; CProductBrowseFactory.fn商品瀏覽紀錄新增(product, productBrowse); List <CProductDetailVM> lsProductDetail = new List <CProductDetailVM>(); CProductDetailVM productDetailVM = new CProductDetailVM() { lsMember = lsMember, MemberSeller = memberseller, Product = product, lsProductPicture = lsProductPicture, lsProductCategory = lsCategory, lsProductComment = lsProductComment, lsProductRank = lsProductRank, Isbanned = Isbanned }; return(View(productDetailVM)); }
public XmlDocument GetProductList(int now_page, string lang_cd, string catg_no1, string catg_no2, string prod_type_cd, string prod_s_init_cd, string prod_e_init_cd, string prod_tag) { XmlDocument doc = new XmlDocument(); CProduct product = new CProduct(); doc.InnerXml = product.GetProductList(now_page, lang_cd, catg_no1, catg_no2, prod_type_cd, prod_s_init_cd, prod_e_init_cd, prod_tag); return(doc); }
public ActionResult DeleteProduct(int?fProductId) { //更新下架時間不再出現於商品展示區 CProduct myProduct = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == fProductId); myProduct.fTheRemovedDate = DateTime.UtcNow.AddHours(08); CProductFactory.fn商品更新(myProduct); return(RedirectToAction("Index")); }
public void CreateAProduct() { CProduct p = new CProduct("111", "Banana", "Produce", 0.5, 10); Assert.Equal("111", p.UniqueID); Assert.Equal("Banana", p.Name); Assert.Equal("Produce", p.Category); Assert.Equal(0.5, p.Price); Assert.Equal(10, p.Quantity); }
public void setProduct(string sSymbol, CSite site, string sLogicID, double dContractSize) { if (m_product == null) { m_product = new CProduct(); } m_product.setSymbol(sSymbol); m_product.setSite(site); m_product.setLogicID(sLogicID); m_product.setContractSize(dContractSize); }
public int DislikeProduct(int ProductId) { CProduct product = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == ProductId); product.fLikeCount -= 1; CProductFactory.fn商品更新(product); int result = product.fLikeCount; return(result); }
public CProduct GetOneProductByNameAndCategory(string name, string category) { using var context = new Project0databaseContext(_contextOptions); var dbProduct = context.Products.FirstOrDefault(x => x.Name == name && x.Category == category); if (dbProduct == null) { return(null); } CProduct p = new CProduct(dbProduct.Productid, dbProduct.Name, dbProduct.Category, dbProduct.Price); return(p); }
public ActionResult AddToCart(string id, BindedProductViewModel bindedProduct) { try { if (!ModelState.IsValid) { ModelState.AddModelError("", "invalid input format"); return(View(bindedProduct)); } // handle concurrency CProduct foundProduct = _storeRepo.GetOneProduct(id); if (foundProduct == null) { ModelState.AddModelError("", "This product has just been deleted"); return(View(bindedProduct)); } CProduct cProduct = new CProduct(foundProduct.UniqueID, foundProduct.Name, foundProduct.Category, foundProduct.Price, bindedProduct.Quantity); // use tempdata to store products in a cart // do not know how to return a serialized string directly, use a local text file for now string path = "../../SimplyWriteData.json"; JsonFilePersist persist = new JsonFilePersist(path); string json = ""; if (TempData.ContainsKey("Cart")) { json = TempData.Peek("Cart").ToString(); } List <CProduct> products = persist.ReadProductsTempData(json); if (products == null) { products = new List <CProduct>(); } products.Add(cProduct); string cart = persist.WriteProductsTempData(products); TempData["Cart"] = cart; TempData.Keep("Cart"); // route parameter is an object return(RedirectToAction("Select", "Store", new StoreViewModel { Storeloc = TempData.Peek("storeLoc").ToString() })); } catch (Exception e) { _logger.LogError(e, "error while tring to add a product"); ModelState.AddModelError("", "failed to create a product"); return(View(bindedProduct)); } }
public ActionResult Create(CProduct product) { using (SqlConnection con = new SqlConnection(connectionStrings)) { con.Open(); string query = "INSERT INTO tProduct VALUES (@fProductName,@fPrice,@fCount)"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@fProductName", product.fProductName); cmd.Parameters.AddWithValue("@fPrice", product.fPrice); cmd.Parameters.AddWithValue("@fCount", product.fCount); cmd.ExecuteNonQuery(); } return(RedirectToAction("Index")); }
public void AddOneProduct(CProduct product) { using var context = new Project0databaseContext(_contextOptions); var newProduct = new Product { Productid = product.UniqueID, Name = product.Name, Category = product.Category, Price = product.Price }; context.Products.Add(newProduct); context.SaveChanges(); }
public IHttpActionResult GetProductsSoldToday(String apiKey) { DateTime dateToday = DateTime.Now.Date; SMS_DBEntities1 db = new SMS_DBEntities1(); var user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey)); if (null != user && user.role_id.Equals("Owner")) { var shop = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id); if (shop != null) { var productsMap = new Dictionary <int, CProduct>(); var cproducts = new List <CProduct>(); IEnumerable <CProduct> distinctList = null; var sales = db.sales.Where(x => x.shop_id == shop.shop_id && DbFunctions.TruncateTime(x.sale_date) == dateToday); foreach (var s in sales) { var product = db.products.FirstOrDefault(x => x.product_id == s.product_id); if (null != product) { var type = db.product_types.FirstOrDefault(y => y.type_id == product.product_type); var brand = db.brands.FirstOrDefault(y => y.brand_id == product.brand_id); var uom = db.msrmnt_units.FirstOrDefault(y => y.sr_no == product.unit_of_msrmnt); var cp = new CProduct(product, type, brand, uom, s.prod_quant); if (!productsMap.ContainsKey(cp.product_id)) { productsMap[cp.product_id] = cp; } else { productsMap[cp.product_id].qty += s.prod_quant; } cproducts.Add(cp); } } distinctList = cproducts.GroupBy(x => x.product_id).Select(x => x.First()); foreach (var p in distinctList) { p.qty = productsMap[p.product_id].qty; } distinctList = distinctList.OrderByDescending(p => p.qty); return(Ok(distinctList)); } } return(BadRequest()); }
public void Create_ValidState() { // arrange var _mockRepo = new Mock <IStoreRepository>(); var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()); tempData["adminLoc"] = storeLoc; var controller = new ProductController(_mockRepo.Object, new NullLogger <ProductController>()) { TempData = tempData }; // bypass duplicate checking _mockRepo.Setup(x => x.GetOneProductByNameAndCategory(It.IsAny <string>(), It.IsAny <string>())) .Returns((CProduct)null); string loc = null; CProduct product = null; int quantity = 0; _mockRepo.Setup(x => x.StoreAddOneProduct(It.IsAny <string>(), It.IsAny <CProduct>(), It.IsAny <int>())) .Callback <string, CProduct, int>((x, y, z) => { loc = x; product = y; quantity = z; }); var viewDP = new DetailedProductViewModel { // ID is automatically assigned Name = "Dying Light 3", Category = "Game", Price = 79.99, Quantity = 100 }; // act IActionResult actionResult = controller.Create(viewDP); // assert Assert.True(controller.ModelState.IsValid); _mockRepo.Verify(r => r.StoreAddOneProduct(It.IsAny <string>(), It.IsAny <CProduct>(), It.IsAny <int>()), Times.Once); Assert.Equal(viewDP.Name, product.Name); Assert.Equal(viewDP.Category, product.Category); Assert.Equal(viewDP.Price, product.Price); Assert.Equal(viewDP.Quantity, quantity); Assert.IsAssignableFrom <RedirectToActionResult>(actionResult); }
// product level public CProduct GetOneProduct(string productID) { using var context = new Project0databaseContext(_contextOptions); var dbProduct = context.Products.FirstOrDefault(x => x.Productid == productID); if (dbProduct == null) { return(null); } CProduct p = new CProduct(dbProduct.Productid, dbProduct.Name, dbProduct.Category, dbProduct.Price); return(p); }
public ActionResult Edit(CProduct product) { using (SqlConnection con = new SqlConnection(connectionStrings)) { con.Open(); string query = "UPDATE tProduct SET fProductName = @fProductName,fPrice = @fPrice,fCount = @fCount where fProductId = @fProductId"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@fProductId", product.fProductId); cmd.Parameters.AddWithValue("@fProductName", product.fProductName); cmd.Parameters.AddWithValue("@fPrice", product.fPrice); cmd.Parameters.AddWithValue("@fCount", product.fCount); cmd.ExecuteNonQuery(); } return(RedirectToAction("Index")); }
// placeholder for more information in the future public ActionResult Details(string id) { string storeLoc = TempData.Peek("adminLoc").ToString(); CProduct foundProduct = _storeRepo.GetOneProductWithQuantity(storeLoc, id); // concurrent if (foundProduct == null) { ModelState.AddModelError("", "Another admin has just deleted this product"); return(View()); } var viewProduct = ViewModelMapper.MapSingleDetailedProduct(foundProduct); return(View(viewProduct)); }
//修改GET抓取JSON資料 //string myProductContent; public JsonResult EditProduct(int?fProductId) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; //防止未登入者進入 CProduct myProduct = CProductFactory.fn商品查詢().FirstOrDefault(p => p.fProductId == fProductId); List <CProductPicture> lsMyProductPicture = CProductPictureFactory.fn商品圖片查詢().Where(p => p.fProductId == fProductId).ToList(); List <CProductCompare> lsProductCategory = CProductCompareFactory.fn商品類別對照查詢().Where(c => c.fProductId == fProductId).ToList(); List <CNoteFolder> lsFolder = CNoteFolderFactory.fn筆記資料夾查詢(member).ToList(); //筆記資料夾包含筆記的列表 List <CNoteFolderViewModel> lsNotefolderVM = new List <CNoteFolderViewModel>(); //讀取筆記資料夾內的筆記 foreach (var folder in lsFolder) { List <CNote> myLsNote = CNoteFactory.fn私人筆記查詢(folder).OrderBy(n => n.fNoteListLevel).Where(n => n.fJsonContent == myProduct.fContent).ToList(); lsNotefolderVM.Add(new CNoteFolderViewModel() { fFolderId = folder.fFolderId, fFolderName = folder.fFolderName, fMemberId = folder.fMemberId, lsNote = myLsNote }); } CNote mynote = CNoteFactory.fn私人筆記全部查詢().FirstOrDefault(n => n.fJsonContent == myProduct.fContent); CShoppingAccountCenterVM ShoppingAccountCenter = new CShoppingAccountCenterVM() { lsCategoryCompare = lsProductCategory, lsProductPicture = lsMyProductPicture, Product = myProduct, lsNotefolderVM = lsNotefolderVM, NoteId = mynote.fNoteId //Content = myProductContent, }; string value = string.Empty; value = JsonConvert.SerializeObject(ShoppingAccountCenter, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Json(value, JsonRequestBehavior.AllowGet)); }
//计算单价 public double CalcPrice(CProduct product, COrderDetail od) { double dblPrice = 0; //如果是促销,取促销价 bool bHasPrice = false; if (Global.GetStore().PromotionMgr.FindByProduct(product.Id) != null) { List <CBaseObject> lstPrice = product.PriceMgr.FindByType(PriceType.Promotion); if (lstPrice.Count > 0) { dblPrice = ((CPrice)lstPrice[0]).Price; bHasPrice = true; } } if (!bHasPrice) { //如果数量符合批发,则取批发价 List <CBaseObject> lstPrice = product.PriceMgr.FindByType(PriceType.Wholesale); if (lstPrice.Count > 0) { for (int i = lstPrice.Count - 1; i >= 0; i--) { CPrice price = (CPrice)lstPrice[i]; if (price.MinOrderNum <= od.Num) { dblPrice = price.Price; bHasPrice = true; break; } } } //如果没有符合,则取零售价 if (!bHasPrice) { List <CBaseObject> lstPrice2 = product.PriceMgr.FindByType(PriceType.Retail); if (lstPrice2.Count > 0) { CPrice price = (CPrice)lstPrice2[0]; dblPrice = price.Price; bHasPrice = true; } } } return(dblPrice); }
//计算总价 public double CalcTotalPrice() { double dblTotal = 0; List <CBaseObject> lstObj = m_Order.OrderDetailMgr.GetList(); foreach (CBaseObject obj in lstObj) { COrderDetail od = (COrderDetail)obj; string sName = ""; CProduct product = (CProduct)Global.GetStore().ProductMgr.Find(od.SP_Product_id); sName = product.Name; //根据数量计算单价 double dblPrice = CalcPrice(product, od); dblTotal += dblPrice * od.Num; } return(dblTotal); }
public CCalcOrderItem() { m_ABC = ""; m_bPartsIsNew = false; m_KOEFF_DIV = 0; m_KOEFF_SEASON_AVG = 0; m_objProduct = null; m_PLAN_FOR_3MONTH = 0; m_PLAN_FOR_3MONTH_IN_WEEK_AVG = 0; m_PREDICTION_FOR_3MONTH = 0; m_PREDICTION_FOR_3MONTH_IN_WEEK_AVG = 0; m_QUANTITY_IN_ORDER = 0; m_QUANTITY_IN_STOCK = 0; m_QUANTITY_IN_WAY = 0; m_QUANTITY_MIN_STOCK_IN_WEEK = 0; m_SALE_FOR_3MONTH = 0; m_SALE_FOR_3MONTH_IN_WEEK_AVG = 0; }
protected void Page_Load(object sender, EventArgs e) { m_PromotionMgr = Global.GetStore().PromotionMgr; m_ProductMgr = Global.GetStore().ProductMgr; string id = Request["id"]; if (string.IsNullOrEmpty(id)) { Response.End(); return; } m_Product = (CProduct)m_ProductMgr.Find(new Guid(id)); if (m_Product == null) { Response.End(); return; } if (!IsPostBack) { lbProductName.Text = m_Product.Name; lbUnit.Text = m_Product.Unit; List <CBaseObject> lstCr = m_Product.ColorInProductMgr.GetList(); rdlistColor.Items.Clear(); foreach (CBaseObject obj in lstCr) { CColorInProduct cr = (CColorInProduct)obj; ListItem item = new ListItem(cr.Name, cr.Id.ToString()); rdlistColor.Items.Add(item); } List <CBaseObject> lstSpec = m_Product.SpecificationInProductMgr.GetList(); rdlistSpecification.Items.Clear(); foreach (CBaseObject obj in lstSpec) { CSpecificationInProduct sp = (CSpecificationInProduct)obj; ListItem item = new ListItem(sp.Name, sp.Id.ToString()); rdlistSpecification.Items.Add(item); } LoadGrid(); } }
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)); }
public ActionResult Edit(string id, DetailedProductViewModel viewDP) { string storeLoc = TempData.Peek("adminLoc").ToString(); try { if (!ModelState.IsValid) { return(View()); } // concurrent var foundProduct = _storeRepo.GetOneProduct(id); if (foundProduct == null) { ModelState.AddModelError("", "Another admin has just deleted this product"); return(View()); } // check if you have changed the name or category if (foundProduct.Name != viewDP.Name || foundProduct.Category != viewDP.Category) { // see if the edited version already exist var editedProduct = _storeRepo.GetOneProductByNameAndCategory(viewDP.Name, viewDP.Category); if (editedProduct != null) { ModelState.AddModelError("", "A record with the same data already exist in this category"); return(View()); } } foundProduct = new CProduct(foundProduct.UniqueID, viewDP.Name, viewDP.Category, viewDP.Price); _storeRepo.EditOneProduct(storeLoc, foundProduct, viewDP.Quantity); return(RedirectToAction(nameof(Index))); } catch (Exception e) { _logger.LogError(e, "error while trying to edit a product"); ModelState.AddModelError("", "failed to edit a product"); return(View()); } }
public List <CProduct> GetAllProductsOfOneOrder(string orderid) { using var context = new Project0databaseContext(_contextOptions); var dbOrder = context.Orderrs.Include(x => x.Orderproducts) .ThenInclude(x => x.Product) .FirstOrDefault(x => x.Orderid == orderid); if (dbOrder == null) { return(null); } List <CProduct> products = new List <CProduct>(); foreach (var product in dbOrder.Orderproducts) { CProduct p = new CProduct(product.Product.Productid, product.Product.Name, product.Product.Category, product.Product.Price, product.Quantity); products.Add(p); } return(products); }