public JsonResult AddTechNote(int ticketId, string note) { //get the ticket that was passed in and pull the associated record //get the current logged on employee (the tech working on the ticket) //this only works cause of stuff we made happen yeah TSTTicket ticket = db.TSTTickets.Single(x => x.TicketID == ticketId); TSTEmployee tech = GetCurrentEmployee(); if (tech != null) { TSTTechNote newNote = new TSTTechNote() { TicketID = ticketId, TechID = tech.EmpID, NotationDate = DateTime.Now, Notation = note }; db.TSTTechNotes.Add(newNote); db.SaveChanges(); var data = new { TechNotes = newNote.Notation, Tech = newNote.TSTEmployee.GetFullName, Date = string.Format("{0:g}", newNote.NotationDate) }; return(Json(data, JsonRequestBehavior.AllowGet)); } return(null); }
/// <summary> /// Notation Information: /// This is the method that is going to be called by jQuery/Ajax from the edit view to add the note on the fly AND post it to the notes section BEFORE submitting the form. /// /// AJAX - Asynchronous JavaScript and XML (makes calles without reloading page) /// /// </summary> public JsonResult AddTechNote(int ticketID, string note) { // get the ticketID passed in to the method and get the associated record TSTTicket ticket = db.TSTTickets.Single(x => x.ID == ticketID); // Get the current logged on employee ( who is working the ticket) TSTEmployee tech = db.TSTEmployees.Single(x => x.Email == User.Identity.Name); // this code requires all employees are associated to a user ID in Identity // This code only works because we associated the TSTEmployee table to the Identity AspNetUser Table // make sure the tech is not null if (tech != null) { // create TstNote object and submit TSTTechNote newNote = new TSTTechNote() { // Property is assigned a value TicketID = ticketID, // passed thru the method TechID = tech.ID, // derived from employee above TimeCreated = DateTime.Now, // hard coded Notes = note // passed in thru the method }; // add note record to the table db.TSTTechNotes.Add(newNote); db.SaveChanges(); //return data to the view to be displayed. This NEVER hits the webserver, so jQuery has NO IDEA what a TSTTechNote. // We send over data that can be parsed by jQuery. var data = new { // On the Fly Variable = newNote.Property, TechNotes = newNote.Notes, Tech = newNote.TSTEmployee.Fname, Date = string.Format("{0:g}", newNote.TimeCreated) // never hits webserver so formatting is done here }; // send note information back to the browser for jQuery to parse return(Json(data, JsonRequestBehavior.AllowGet)); } return(null); }