public ActionResult AddOrderForSales() { ApplicationDbContext context = new ApplicationDbContext(); string currentUserId = User.Identity.GetUserId(); IList <Customer> customers = context.Customers.Where(x => x.SalesPerson.Id == currentUserId).ToList(); AddOrderForSalesViewModel model = new AddOrderForSalesViewModel(); model.Customers = customers.Select(u => new SelectListItem { Text = u.Name, Value = u.Id.ToString() }); model.Date = DateTime.Now; return(View(model)); }
public async Task <ActionResult> AddOrderForSales(AddOrderForSalesViewModel model) { if (!ModelState.IsValid) { return(View(model)); } ApplicationDbContext context = new ApplicationDbContext(); context.Orders.Add(new Order { CustomerId = Convert.ToInt32(model.CustomerId), Name = model.Name, Date = model.Date }); await context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); }