/// <summary> /// Gets Index page when Edit/Index is hit /// </summary> /// <returns> /// Index View /// </returns> public async Task <ViewResult> Index() { try { Authorize(); } catch (HttpResponseException e) { return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page"))); } try { RecordRetriever rr = new RecordRetriever(); var res = rr.RetrieveRecords(1000); return(View("Index", res)); } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Posts edited ticket data entry to DataEditor service /// </summary> /// <param name="td">TicketData instance from edit form</param> /// <returns>Index View</returns> public async Task <ViewResult> PostEdit(TicketData td) { try { Authorize(); } catch (HttpResponseException e) { return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page"))); } try { DataEditor de = new DataEditor(); UserData loggedInUser = Auth0APIClient.GetUserData(User.Claims.First().Value); de.PostEditor(td, loggedInUser); RecordRetriever rr = new RecordRetriever(); var res = rr.RetrieveRecords(1000); return(View("Index", res)); } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Posts the ticket entry to be closed to the DataEntry.CloseTicket service /// </summary> /// <param name="td">TicketData entry to close</param> /// <returns>HomePage view with Open records</returns> public async Task <ViewResult> PostEntryClose(TicketData td) { try { Authorize(); } catch (HttpResponseException e) { return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page"))); } try { DataEntry de = new DataEntry(); RecordRetriever rr = new RecordRetriever(); de.CloseTicket(td); var tdRes = rr.RetrieveRecords(numberOfRecords); return(View("HomePage", tdRes)); } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Displays EditForm view with TicketData instance as the model /// </summary> /// <param name="td">TicketData instance</param> /// <returns>EditForm View with specified TicketData entry</returns> public async Task <ViewResult> EditForm(TicketData td) { try { Authorize(); } catch (HttpResponseException e) { return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page"))); } try { RecordRetriever rr = new RecordRetriever(); var tdRes = rr.GetRecordByID(td.EntryId); return(View("EditForm", tdRes)); } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Endpoint to create a new user in the database and Auth0 /// </summary> /// <param name="newUser"></param> /// <returns></returns> public async Task <ViewResult> CreateUser(Users newUser) { try { Authorize(); } catch (HttpResponseException e) { return(View("Error", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page"))); } UserManager um = new UserManager(); try { um.CreateUser(newUser, Auth0APIClient.GetUserData(User.Claims.First().Value)); return(View("UsersHome", um.GetUsers())); } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Gets the HomePage view with current open records /// </summary> /// <returns>HomePage view with open records</returns> public async Task <ViewResult> HomePage() { try { if (User.Identity.IsAuthenticated) { RecordRetriever rr = new RecordRetriever(); var records = rr.RetrieveRecords(numberOfRecords); return(View("HomePage", records)); } else { return(View("Landing")); } } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Creates an HttpResponseMessage given an Exception /// </summary> /// <param name="e"></param> /// <returns></returns> public static HttpResponseMessage CreateResponseMessage(Exception e) { string guid = ExceptionReporter.DumpException(e); HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.InternalServerError); message.Content = new StringContent(e.Message + "|" + guid); return(message); }
public void DumpExceptionTest() { string guid = ExceptionReporter.DumpException(new Exception()); var actual = Guid.Parse(guid); var expected = Guid.NewGuid(); Assert.IsNotNull(guid); Assert.AreEqual(actual.GetType(), expected.GetType()); }
public async Task Login() { try { await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties() { RedirectUri = "/" }); } catch (Exception e) { ExceptionReporter.DumpException(e); } }
/// <summary> /// Function to create a basic exception view /// </summary> /// <param name="exception"></param> /// <param name="guid"></param> /// <returns></returns> public static ErrorViewModel CreateBasicExceptionView(Exception exception, string guid) { ErrorViewModel errorView = new ErrorViewModel(); try { errorView.ErrorCode = guid; errorView.Reason = exception.Message; } catch (Exception e) { ExceptionReporter.DumpException(e); } return(errorView); }
/// <summary> /// Endpoint to run the selected report /// </summary> /// <param name="reportData"></param> /// <returns></returns> public async Task <JsonResult> RunReport(ReportInput reportData) { try { Authorize(); } catch (HttpResponseException e) { return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } HttpResponseMessage resp = null; try { ReportGenerator rg = new ReportGenerator(); resp = await rg.GenerateReport(reportData); var content = resp.Content; var bytes = await resp.Content.ReadAsByteArrayAsync(); return(Json(new { content = content, data = bytes })); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Gets the TicketData entry based on Entry ID of ticket clicked on in HomePage table /// </summary> /// <param name="entryID">Entry ID specified in HomePage table</param> /// <returns>JSON containing redirect URL</returns> public async Task <JsonResult> OpenEntry(string entryID) { try { Authorize(); } catch (HttpResponseException e) { return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } try { using (var context = new TicketingSystemDBContext()) { int id = int.Parse(entryID); RecordRetriever rr = new RecordRetriever(); TicketData td = rr.GetRecordByID(id); return(Json(new { newUrl = Url.Action("EntryClose", "Home", td) })); } } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Endpoint that returns a list of valid emails in the system /// </summary> /// <returns></returns> public async Task <JsonResult> GetEmails() { try { Authorize(); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } try { UserManager um = new UserManager(); List <string> emails = new List <string>(); foreach (Users u in um.GetUsers()) { emails.Add(u.Email); } return(Json(new { emails = emails })); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Endpoint to delete an entry from the database /// </summary> /// <param name="entryId"></param> /// <returns></returns> public async Task <JsonResult> RemoveEntry(string entryId) { try { Authorize(); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } try { DataEditor de = new DataEditor(); de.DeleteEntry(entryId, Auth0APIClient.GetUserData(User.Claims.First().Value)); return(Json(new { newUrl = Url.Action("Index", "Edit"), message = "Deleted entry", id = entryId })); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Create an ErrorViewModel to display to the user /// </summary> /// <param name="exception"></param> /// <param name="reason"></param> /// <returns></returns> public static ErrorViewModel CreateHttpErrorView(HttpResponseException exception, string reason) { ErrorViewModel errorView = new ErrorViewModel(); try { int code = (int)exception.Response.StatusCode; string status = exception.Response.StatusCode.ToString(); errorView.ErrorCode = code + " " + status; errorView.Reason = reason; } catch (Exception e) { ExceptionReporter.DumpException(e); } return(errorView); }
/// <summary> /// Gets the TicketData entry based on the entryID input in Index page /// </summary> /// <param name="entryId">Entry ID input from index</param> /// <returns>JSON holding redirect URL</returns> public async Task <JsonResult> GetRecord(string entryId) { try { Authorize(); } catch (HttpResponseException e) { return(Json(new { newUrl = Url.Action("Error", "Edit", Utility.CreateHttpErrorView(e, "You do not have the permissions to view this page")) })); } try { using (var context = new TicketingSystemDBContext()) { RecordRetriever rr = new RecordRetriever(); var result = rr.GetRecordByID(int.Parse(entryId)); return(Json(new { newUrl = Url.Action("EditForm", "Edit", result) })); } } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Endpoint to delete a user from the database and Auth0 /// </summary> /// <param name="userId"></param> /// <returns></returns> public async Task <JsonResult> ToggleActivation(string userId) { try { Authorize(); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } UserManager um = new UserManager(); try { um.ToggleActivation(int.Parse(userId)); return(Json(new { newUrl = Url.Action("UsersHome", um.GetUsers()), message = "Changed User Status", id = userId })); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Endpoint to ImportUsers from Auth0 /// </summary> /// <returns></returns> public async Task <JsonResult> ImportUsers() { try { Authorize(); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } try { UserManager um = new UserManager(); um.ImportUsersFromAuth0(); return(Json(new { message = "successful import", newUrl = Url.Action("UsersHome", um.GetUsers()) })); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
/// <summary> /// Endpoint to return all the permissions associated with a given user /// </summary> /// <returns>JSON containing permissions</returns> public async Task <JsonResult> Permissions() { try { Authorize(); } catch (HttpResponseException e) { return(Json(new { newUrl = Url.Action("Error", Utility.CreateHttpErrorView(e, "401 Unauthorized")) })); } try { var userId = User.Claims.First().Value; UserData ud = Auth0APIClient.GetUserData(userId); List <UserPermission> permissions = Auth0APIClient.GetPermissions(ud.user_id); return(Json(new { permissions = permissions })); } catch (HttpResponseException e) { string guid = ExceptionReporter.DumpException(e); ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(Json(new { newUrl = Url.Action("ServerError", error) })); } catch (Exception e) { string guid = ExceptionReporter.DumpException(e); return(Json(new { newUrl = Url.Action("Error", Utility.CreateBasicExceptionView(e, guid)) })); } }
public async Task Logout() { try { await HttpContext.SignOutAsync("Auth0", new AuthenticationProperties { // Indicate here where Auth0 should redirect the user after a logout. // Note that the resulting absolute Uri must be whitelisted in the // **Allowed Logout URLs** settings for the client. RedirectUri = Url.Action("Landing", "Home") }); await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); } catch (Exception e) { ExceptionReporter.DumpException(e); } }
/// <summary> /// Endpoint to get only open records /// </summary> /// <returns></returns> public async Task <ViewResult> OpenTickets() { try { RecordRetriever rr = new RecordRetriever(); var records = rr.GetOpenRecords(numberOfRecords); return(View("HomePage", records)); } catch (HttpResponseException e) { ServerErrorViewModel error = await Utility.CreateServerErrorView(e); return(View("ServerError", error)); } catch (Exception e) { var guid = ExceptionReporter.DumpException(e); ErrorViewModel error = Utility.CreateBasicExceptionView(e, guid); return(View("Error", error)); } }
/// <summary> /// Function to create a ServerErrorViewModel to display to the user /// </summary> /// <param name="exception"></param> /// <param name="reason"></param> /// <returns></returns> public static async Task <ServerErrorViewModel> CreateServerErrorView(HttpResponseException exception) { ServerErrorViewModel errorView = new ServerErrorViewModel(); string response = await exception.Response.Content.ReadAsStringAsync(); var strings = response.Split("|"); string reason = strings[0]; string guid = strings[1]; try { int code = (int)exception.Response.StatusCode; string status = exception.Response.StatusCode.ToString(); errorView.ErrorCode = code + " " + status; errorView.Message = "Please contact your system administrator with the following error code"; errorView.Reason = reason; errorView.Guid = guid; } catch (Exception e) { ExceptionReporter.DumpException(e); } return(errorView); }
public void CreateBasicExceptionViewTest() { Exception e = new Exception("Testing exception methods"); ErrorViewModel error = Utility.CreateBasicExceptionView(e, ExceptionReporter.DumpException(e)); }