public HomeModule() { Get["/"] = _ => View["index"]; Post["api/newcall"] = _ => { try { var posts = this.Bind<NewCallObject>(); var rnd = new Random(); var sc = new SupportCall { RecordID = Guid.NewGuid(), AssignedTo = Guid.Parse(posts.assignTo), Customer = Guid.Parse(posts.contact), CreatedBy = Guid.Parse(posts.createdBy), CustomerReference = posts.customerRef, CustomerSite = Guid.Parse(posts.location), Product = Convert.ToInt32(posts.product), InternalReference = "MHA" + rnd.Next(1736, 9999), Status = 0, CreatedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now }; var Initialnote = new Note { CallRecordID = sc.RecordID, RecordID = Guid.NewGuid(), CreatedBy = sc.CreatedBy, NoteType = 6, NoteSubType = Convert.ToInt32(posts.prc), NoteText = posts.issueDescription, TimeSpent = 0, CreatedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now }; var note = new Note { CallRecordID = sc.RecordID, RecordID = Guid.NewGuid(), CreatedBy = sc.CreatedBy, NoteType = 0, NoteSubType = Convert.ToInt32(posts.prc), NoteText = posts.prcDescription, TimeSpent = 0, CreatedDateTime = DateTime.Now, UpdatedDateTime = DateTime.Now }; if (sc.Save()) { if (Initialnote.Save()) { return note.Save() ? HttpStatusCode.OK : HttpStatusCode.BadRequest; } return HttpStatusCode.BadRequest; } return HttpStatusCode.BadRequest; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return HttpStatusCode.BadRequest; } }; Get["api/supportCalls"] = _ => { var calls = SupportCall.ToList(); return Response.AsJson(calls); }; Get["api/loadNotes/{id}"] = _ => { var id = Guid.Parse(_.id); List<NoteDTO> notes = Note.LoadFromCall(id); return Response.AsJson(notes); }; Get["api/export"] = _ => { return Export.ExportToCSV(); }; Post["api/addNote"] = _ => { var posts = this.Bind<NewNoteObject>(); var note = new Note { CreatedBy = Guid.Parse(posts.CreatedBy), CallRecordID = Guid.Parse(posts.CallRecordID), CreatedDateTime = DateTime.Now, NoteSubType = Convert.ToInt32(posts.NoteSubType), NoteText = posts.NoteText, NoteType = Convert.ToInt32(posts.noteType), RecordID = Guid.NewGuid(), TimeSpent = Convert.ToDouble(posts.TimeSpent), UpdatedDateTime = DateTime.Now }; try { if (note.Save()) { SMTP.SendEmail("*****@*****.**", "Test Email", "This is a test e-mail"); return HttpStatusCode.OK; } } catch (Exception e) { Console.WriteLine(e.Message); } return HttpStatusCode.BadRequest; }; Post["api/addContact"] = _ => { var posts = this.Bind<NewContact>(); var con = new CustomerContact { RecordID = Guid.NewGuid(), CustomerSite = posts.customerSite, Name = posts.Name, Email = posts.Email, PhoneNumber = posts.Phone, MobileNumber = posts.Mobile, }; try { if (con.Save()) { return HttpStatusCode.OK; } } catch (Exception e) { Console.WriteLine(e.Message); } return HttpStatusCode.BadRequest; }; Post["api/updateContact"] = _ => { var posts = this.Bind<UpdateContact>(); var con = CustomerContact.Load(posts.RecordID); con.CustomerSite = posts.customerSite; con.Name = posts.Name; con.Email = posts.Email; con.PhoneNumber = posts.Phone; con.MobileNumber = posts.Mobile; try { if (con.Save()) { return HttpStatusCode.OK; } } catch (Exception e) { Console.WriteLine(e.Message); } Console.Write(CustomerContact.LastError.ToString()); return HttpStatusCode.BadRequest; }; Get["api/updateCall/{id}/{status}"] = _ => { Guid g = Guid.Parse(_.id); int status = _.status; var sc = SupportCall.Load(g); sc.Status = status; try { if (sc.Save()) { return HttpStatusCode.OK; } } catch (Exception e) { Console.WriteLine(e.Message); } Console.Write(SupportCall.LastError.ToString()); return HttpStatusCode.BadRequest; }; }