// GET: Purchases/Create public IActionResult Create() { var suppdata = from e in _context.Suppliers.Distinct() select e; var purchasedata = from a in _context.Purchase select a; //Purchase purchasedata = new Purchase(); List <SelectListItem> supplist = new List <SelectListItem>(); foreach (var item in suppdata) { supplist.Add(new SelectListItem() { Text = item.Sname, Value = item.Sid }); } /* * ViewBag.supp = supplist; * return View(); */ PurchasesIndexViewModel pViewModel = new PurchasesIndexViewModel(); pViewModel.SupplierList = supplist; pViewModel.Purchase = purchasedata.Take(0); //Create View所使用的Dropdownlistfor控制項名稱和此句有關,若只指定名稱而無此句,則會出現來源錯誤 //Take()若不為0,則在Create的View上會顥示Purchasedata所查詢出來的資料;Take(0)為固定查詢結果的最大筆數 //pViewModel.SupperList = new SelectList(suppdata, "Sid", "Sname"); return(View(pViewModel)); }
// GET: Purchases public ActionResult Index([Bind("Sid")] Purchase purchase, string Spname) { var purchasedata = from s in _context.Suppliers join p in _context.Purchase on s.Sid equals p.Sid orderby s.Sid select new { s, p }; List <SelectListItem> supplist = new List <SelectListItem>(); foreach (var item in purchasedata.Select(e => e.s).Distinct().OrderBy(e => e.Sid)) { supplist.Add(new SelectListItem { Text = item.Sname, Value = item.Sid }); } if (string.IsNullOrEmpty(purchase.Sid) != true) { purchasedata = purchasedata.Where(e => e.p.Sid == purchase.Sid); } if (string.IsNullOrEmpty(Spname) != true) { purchasedata = purchasedata.Where(e => e.p.Spname.Contains(Spname)); } PurchasesIndexViewModel PViewModel = new PurchasesIndexViewModel { Supplier = purchasedata.Select(e => e.s).Distinct(), Purchase = purchasedata.Select(e => e.p), SupplierList = supplist }; return(View(PViewModel)); }
public IActionResult Index() { var model = new PurchasesIndexViewModel(); model.Purchases = _purchasesService.GetPurchases(); return(View("Index", model)); }
public async Task <IActionResult> GetDeactivatedPurchasesByUser() { var model = new PurchasesIndexViewModel(); string userId = _userManager.GetUserId(User); var operationDetails = await _purchasesService.GetPurchaseByUserId(userId); if (!operationDetails.Succedeed) { return(View("Index", model.StatusMessage = operationDetails.Message)); } model.Purchases = operationDetails.Property.Where(x => x.IsActive == false); return(View("Index", model)); }