public ActionResult Assign(JobCardViewModel jobCardViewModel) { IUnitOfWork testUnit = new UnitOfWork(_context); testUnit.JobCards.SingleOrDefault(s => s.Id == jobCardViewModel.Id); // var job = Mapper.Map <JobCardViewModel, JobCard>(jobCardViewModel); job.ScheduledFor = jobCardViewModel.ScheduledFor; job.JobStatusId = 2; job.CustomerId = jobCardViewModel.CustomerId; var userList = new List <ApplicationUser>(); foreach (var userId in jobCardViewModel.ApplicationUserIdArray) { var user = _context.Users.SingleOrDefault(s => s.Id == userId); userList.Add(user); PushBullet.Assigned(user.Id); } job.ApplicationUsers = userList; testUnit.JobCards.Update(job); testUnit.Complete(); return(RedirectToAction("Index")); }
public ActionResult Create(JobCardViewModel jobCardViewModel) { if (ModelState.IsValid) { IUnitOfWork testUnit = new UnitOfWork(_context); var job = Mapper.Map <JobCardViewModel, JobCard>(jobCardViewModel); job.CreatedAt = DateTime.Now; job.ScheduledFor = jobCardViewModel.ScheduledFor; var customer = testUnit.Customers.SingleOrDefault(f => f.Id == jobCardViewModel.CustomerId); job.Customer = customer; var userList = new List <ApplicationUser>(); foreach (var userId in jobCardViewModel.ApplicationUserIdArray) { var user = _context.Users.SingleOrDefault(s => s.Id == userId); userList.Add(user); PushBullet.Assigned(userId); } job.ApplicationUsers = userList; testUnit.JobCards.Add(job); testUnit.Complete(); return(RedirectToAction("Index")); /* * Note: * This Code was used to pull the current user as the person the job is allocated to. * //var userId = User.Identity.GetUserId(); * //var userFromDb = _context.Users.SingleOrDefault(u => u.Id == userId); * //job.ApplicationUsers.Add(userFromDb); */ } return(View(jobCardViewModel)); }