예제 #1
0
        /// <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));
            }
        }
예제 #2
0
        /// <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));
            }
        }
예제 #3
0
        /// <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));
            }
        }
예제 #4
0
        /// <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));
            }
        }
예제 #5
0
        /// <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));
            }
        }
예제 #6
0
        /// <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));
            }
        }
예제 #7
0
        /// <summary>
        /// Gets the model for the page
        /// </summary>
        /// <param name="currentPage">The current page</param>
        /// <returns>The page model</returns>
        public virtual ServerErrorViewModel GetError500Model(IPublishedContent currentPage)
        {
            var model = new ServerErrorViewModel
            {
                Metadata = _metadataHandler.GetMetadata(currentPage)
            };
            Mapper.Map(currentPage, model);

            return model;
        }
예제 #8
0
        /// <summary>
        /// Gets the model for the page
        /// </summary>
        /// <param name="currentPage">The current page</param>
        /// <returns>The page model</returns>
        public virtual ServerErrorViewModel GetError500Model(IPublishedContent currentPage)
        {
            var model = new ServerErrorViewModel
            {
                Metadata = _metadataHandler.GetMetadata(currentPage)
            };

            Mapper.Map(currentPage, model);

            return(model);
        }
예제 #9
0
        /// <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))
                }));
            }
        }
예제 #10
0
        /// <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))
                }));
            }
        }
예제 #11
0
        /// <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))
                }));
            }
        }
예제 #12
0
        /// <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))
                }));
            }
        }
예제 #13
0
        /// <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))
                }));
            }
        }
예제 #14
0
        /// <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))
                }));
            }
        }
예제 #15
0
        /// <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))
                }));
            }
        }
예제 #16
0
        /// <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))
                }));
            }
        }
예제 #17
0
        /// <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));
            }
        }
예제 #18
0
        /// <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);
        }
예제 #19
0
 /// <summary>
 /// Endpoint to create a 401 error page
 /// </summary>
 /// <returns></returns>
 public ViewResult ServerError(ServerErrorViewModel error)
 {
     return(View("Error", error));
 }
        public async void CreateServerErrorViewTest(HttpResponseException exception)
        {
            ServerErrorViewModel result = await Utility.CreateServerErrorView(exception);

            Assert.IsNotNull(result);
        }