public async Task <IActionResult> AddNote(int id, JobAddNoteViewModel jobNote) { var note = new JobAddNoteViewModel() { User = await _userManager.GetUserAsync(User), Id = id, CompanyName = jobNote.CompanyName, Note = jobNote.Note }; var jn = new JobNotes() { User = note.User, JobId = id, Notes = note.Note }; if (id != jobNote.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.JobNotes.Add(jn); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobExists(jobNote.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(note)); }
public async Task <IActionResult> Create(JobCreateViewModel job) { //create new instance of company var c = new Company(); if (_context.Company.Any(com => com.Name == job.Company)) { c = _context.Company.SingleOrDefault(com => com.Name == job.Company); } else { c.Name = job.Company; _context.Company.Add(c); _context.SaveChanges(); } //create new instance of job var j = new Job() { CompanyId = c.Id, JobTitle = job.JobTitle }; _context.Job.Add(j); _context.SaveChanges(); //create new instance of jobnote var note = new JobNotes() { User = await _userManager.GetUserAsync(User), JobId = j.Id, Notes = job.Note, }; _context.JobNotes.Add(note); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); }