public List <OrderViewModel> GetListActive() { var result = new List <OrderViewModel>(); var listOrder = orderRepo.GetAll().ToList(); var listCategoryProduct = categoryProductRepo.GetAll().ToList(); var listStore = storeRepo.GetAll().ToList(); var listUser = userRepo.GetAll().ToList(); var listOrderDetail = orderDetailRepo.GetAll().ToList(); foreach (var item in listOrder) { //var category = listCategoryProduct.FirstOrDefault(c => c.Id == item.CategoryId); var store = listStore.FirstOrDefault(s => s.Id == item.StoreId); var sender = listUser.FirstOrDefault(u => u.Id == item.SenderId); var recipient = listUser.FirstOrDefault(u => u.Id == item.RecipientId); var orderDetail = listOrderDetail.Where(o => o.orderId == item.Id); var customerConfirm = listUser.FirstOrDefault(u => u.Id == item.CustomerConfirmId); var orderVM = new OrderViewModel(); orderVM.MapOrderTblToOrderViewModel(item, store, sender, recipient, customerConfirm, orderDetail); result.Add(orderVM); } return(result); }
// GET: OrderController/Create public ActionResult Create() { var listCategory = categoryProductRepo.GetAll().ToList(); var listStore = storeRepo.GetAll().ToList(); var listUser = userRepo.GetAll().ToList(); ViewBag.ListCategory = new SelectList(listCategory, "Id", "Name"); ViewBag.ListStore = new SelectList(listStore, "Id", "Name"); ViewBag.ListSender = new SelectList(listUser, "Id", "UserName"); ViewBag.ListRecipient = new SelectList(listUser, "Id", "UserName"); return(View()); }