コード例 #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
        public TicketData CreateTestData()
        {
            using (var context = new TicketingSystemDBContext())
            {
                JobType j = new JobType();
                j.JobName = "Miscellaneous";

                RecordRetriever rr      = new RecordRetriever();
                var             records = rr.RetrieveRecords(10);

                Users ticketWorker = context.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
                Users entryAuthor  = context.Users.Where(w => w.FullName == "Test User").FirstOrDefault();

                TicketData td = new TicketData()
                {
                    TripNum        = -1,
                    StageNum       = "S01",
                    JobType        = j,
                    EntryAuthor    = entryAuthor,
                    EntryAuthorId  = entryAuthor.UserId,
                    TicketWorker   = ticketWorker,
                    TicketWorkerId = ticketWorker.UserId,
                    WorkerName     = "Test User",
                    StartTime      = "12:00",
                    EndTime        = "12:00",
                    StartDate      = DateTime.Today,
                    EndDate        = DateTime.Today,
                    Comments       = "Entry generated by HomeController.PostEntry unit test"
                };
                return(td);
            }
        }
コード例 #4
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));
            }
        }
コード例 #5
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));
            }
        }
コード例 #6
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));
            }
        }
コード例 #7
0
        public void GetOpenRecordsTest()
        {
            RecordRetriever rr  = new RecordRetriever();
            var             res = rr.GetOpenRecords(10);

            Assert.IsNotNull(res);
            Assert.IsTrue(res.GetType() == typeof(List <TicketData>));
        }
コード例 #8
0
        public void RetrieveRecordsTest()
        {
            RecordRetriever          rr        = new RecordRetriever();
            var                      res       = rr.RetrieveRecords(10);
            IEnumerable <TicketData> testModel = new List <TicketData>();

            Assert.IsNotNull(res);
            Assert.IsTrue(res.GetType() == testModel.GetType());
        }
コード例 #9
0
        public async Task PostEditorTest(TicketData td)
        {
            using (var db = new TicketingSystemDBContext())
            {
                ViewResult result = await ec.PostEdit(td);

                RecordRetriever rr       = new RecordRetriever();
                ViewResult      testView = View("Index", rr.RetrieveRecords(10));

                Assert.IsNotNull(result);
                Assert.AreEqual(testView.ViewName, result.ViewName);
            }
        }
コード例 #10
0
 public void GetRecordByIDTest()
 {
     using (var context = new TicketingSystemDBContext())
     {
         var       td     = TestUtility.CreateTestData();
         DataEntry de     = new DataEntry();
         Users     dbUser = context.Users.Where(u => u.FullName == "Test User").FirstOrDefault();
         de.PostEntry(td, Auth0APIClient.GetUserData(dbUser.Auth0Uid));
         int             id  = context.TicketData.First().EntryId;
         RecordRetriever rr  = new RecordRetriever();
         var             res = rr.GetRecordByID(id);
         Assert.IsNotNull(res);
         Assert.IsTrue(res.GetType() == typeof(TicketData));
     }
 }
コード例 #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>
        /// 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))
                }));
            }
        }
コード例 #13
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));
            }
        }