public IActionResult CreateServiceOrder() { var techs = _context.Users.OrderBy(u => u.Email).Select(x => x.Email); var clients = _context.Clients.ToList(); var model = new CreateServiceOrderViewModel { TeamMembers = new SelectList(techs), Clients = clients.Select(c => new SelectListItem() { Text = c.Name.ToString() }), }; return(View(model)); }
public async Task <IActionResult> CreateServiceOrder(CreateServiceOrderViewModel ct) { var client = _context.Clients.SingleOrDefault(c => c.Name == ct.Client); ServiceOrder t = new ServiceOrder { Title = ct.Title, Description = ct.Description, AssignedTo = await _userManager.FindByEmailAsync(ct.AssignedTo), CreateDate = DateTime.Now, DueDate = ct.DueDate, Client = client }; var user = await _userManager.GetUserAsync(User); t.Creator = user; _context.Add(t); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }