Exemplo n.º 1
0
 public ActionResult Create(CreateTransactionVewModel viewModel)
 {
     _db.Transactions.Add(new Transaction
     {
         CustomerId = viewModel.CustomerId,
         ProductId  = viewModel.ProductId
     });
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 2
0
        // ViewData/ViewBags --covering this later
        // GET: Transaction/Create
        public ActionResult Create()
        {
            var viewModel = new CreateTransactionVewModel();

            // code to fill drop down list
            viewModel.Products = _db.Products.Select(p => new SelectListItem
            {
                Text  = p.Name,
                Value = p.ProductId.ToString()
            });

            viewModel.Customers = _db.Customers.Select(c => new SelectListItem
            {
                Text  = c.FirstName + " " + c.LastName,
                Value = c.CustomerId.ToString()
            });

            return(View(viewModel));
        }