public IActionResult GetIncidentsReport([FromBody] DatesFilter datesFilter)
        {
            ResponseModelWithData <IEnumerable <IncidentReportModel> > responseModel = new ResponseModelWithData <IEnumerable <IncidentReportModel> >();

            try
            {
                var token = Utils.GetToken(Request);

                var dateFrom = new DateTime(datesFilter.YearFrom, datesFilter.MonthFrom, datesFilter.DayFrom);
                var dateTo   = new DateTime(datesFilter.YearTo, datesFilter.MonthTo, datesFilter.DayTo);

                var admin = sessionService.AuthorizeAdminByToken(token);

                var list = trajectService.GetIncidentsReport(admin, dateFrom, dateTo);

                responseModel.Data         = IncidentReportModel.ToModel(list);
                responseModel.IsResponseOK = true;

                return(Ok(responseModel));
            }
            catch (HandledException he)
            {
                responseModel.IsResponseOK = false;
                responseModel.ErrorMessage = he.Message;

                return(Ok(responseModel));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Exemplo n.º 2
0
        public IActionResult GetIncidentReportById(long incidentId)
        {
            var incidentReport = new IncidentReportModel();

            var incident   = service.GetIncidentById(incidentId);
            var staff      = service.GetUsersByIncidentId(incidentId);
            var staffNames = new List <string>();
            var photos     = service.GetIncidentPhotosByIncidentId(incidentId);
            var photoUrls  = new List <string>();

            foreach (var item in staff)
            {
                staffNames.Add(item.Forename + " " + item.Surname);
            }

            foreach (var item in photos)
            {
                photoUrls.Add(item.Url);
            }

            incidentReport.IncidentId  = incidentId;
            incidentReport.Injury      = incident.Injury;
            incidentReport.PhotoUrl    = photoUrls;
            incidentReport.Description = incident.Description;
            incidentReport.StaffNames  = staffNames;
            //incidentReport.Date = incident.Date;

            return((incidentReport != null) ? CreateResponse(new ResultModel <IncidentReportModel>(incidentReport, "Success")) : DataNotFoundResponse("Get Data Failed"));
        }
Exemplo n.º 3
0
        public void ListTest()
        {
            //Arrange
            var item = new IncidentReportModel {
                CreationUser = "******"
            };
            var outModel = new JobseekerModel {
                JobSeekerId = 3187026003, IncidentReports = new List <IncidentReportModel> {
                    item
                }
            };
            var inModel = new JobseekerModel {
                JobSeekerId = 3187026003
            };

            mockMappingEngine.Setup(m => m.Map <JobSeekerIncidentReportListRequest>(It.IsAny <JobseekerModel>())).Returns(new JobSeekerIncidentReportListRequest());
            mockIRWcf.Setup(m => m.List(It.IsAny <JobSeekerIncidentReportListRequest>())).Returns(new JobSeekerIncidentReportListResponse());
            mockMappingEngine.Setup(m => m.Map <JobseekerModel>(It.IsAny <JobSeekerIncidentReportListResponse>())).Returns(outModel);

            //act
            var result = SystemUnderTest().GetAllIncidentReport(inModel);

            //Assert
            Assert.IsTrue(result.IncidentReports.Count() > 0);
            Assert.IsTrue(result.IncidentReports.ElementAt(0).CreationUser == "SR0663_D");
            mockMappingEngine.Verify(m => m.Map <JobSeekerIncidentReportListRequest>(It.IsAny <JobseekerModel>()), Times.Once());
            mockIRWcf.Verify(m => m.List(It.IsAny <JobSeekerIncidentReportListRequest>()), Times.Once());
            mockMappingEngine.Verify(m => m.Map <JobseekerModel>(It.IsAny <JobSeekerIncidentReportListResponse>()), Times.Once());
        }
Exemplo n.º 4
0
        public IActionResult AddIncident()
        {
            ViewBag.StaffList = staff;

            IncidentReportModel incidentReport = new IncidentReportModel()
            {
                StaffNames = new List <string>()
                {
                    ""
                }
            };

            return(View(incidentReport));
        }
Exemplo n.º 5
0
        public IActionResult Incident(long incidentId)
        {
            ViewBag.IsForm = false;
            IncidentReportModel incidentReport = incidentReports.Where(i => i.IncidentId == incidentId).FirstOrDefault();
            var name      = HttpContext.Session.GetString("Name");
            var firstName = name.Substring(0, name.IndexOf(" "));

            var user = HttpContext.Session.GetString("UserType");

            ViewBag.IsStaff = user.Equals("staff");

            var description = descriptions.Where(m => m.Key == incidentReport.IncidentId).FirstOrDefault();

            incidentReport.Description = string.Format(description.Value, firstName);

            return(View(incidentReport));
        }
Exemplo n.º 6
0
        public IActionResult AddIncident(IncidentReportModel incidentReport, string submitButton)
        {
            ViewBag.StaffList = staff;

            if (incidentReport.StaffNames.Count < 1)
            {
                ModelState.AddModelError("StaffNames", "Please select staff member");
            }
            else if (incidentReport.StaffNames.Contains("0"))
            {
                ModelState.AddModelError("StaffNames", "Please select staff member");
            }

            if (incidentReport.Date == null)
            {
                ModelState.AddModelError("Date", "Please select date");
            }

            if (incidentReport.Time == null)
            {
                ModelState.AddModelError("Time", "Please select time");
            }

            switch (submitButton)
            {
            case "Add Staff":
                incidentReport.StaffNames.Add("");
                return(View(incidentReport));

            case "Next":
                if (!ModelState.IsValid)
                {
                    return(View(incidentReport));
                }

                ViewBag.UploadEnabled = false;
                ViewBag.PhotoSelected = false;
                return(View("AddInjury", incidentReport));

            default:
                return(View());
            }
        }
Exemplo n.º 7
0
        public IActionResult IncidentReport(IncidentReportModel incidentReport, bool isForm = false)
        {
            if (string.IsNullOrEmpty(incidentReport.Description))
            {
                ModelState.AddModelError("Description", "Please enter a report");
            }

            var user = HttpContext.Session.GetString("UserType");

            ViewBag.IsStaff = user.Equals("staff");

            if (!ModelState.IsValid)
            {
                return(View(incidentReport));
            }

            ViewBag.IsForm      = isForm;
            incidentReport.Date = incidentReport.Date + incidentReport.Time;
            return(View("Incident", incidentReport));
        }
Exemplo n.º 8
0
        public IActionResult AddInjury(IncidentReportModel incidentReport, string submitButton)
        {
            if (string.IsNullOrEmpty(incidentReport.Injury))
            {
                ModelState.AddModelError("Injury", "Please enter injury");
            }

            if (string.IsNullOrEmpty(incidentReport.InjuryArea))
            {
                ModelState.AddModelError("InjuryArea", "Please enter injury areas");
            }

            ViewBag.PhotoSelected = false;
            switch (submitButton)
            {
            case "Upload":
                var files = HttpContext.Request.Form.Files;

                if (incidentReport.PhotoUrl == null)
                {
                    incidentReport.PhotoUrl = new List <string>();
                }

                foreach (var file in files)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');

                    var path = Path.Combine(_environment.WebRootPath, "images/incident_images", fileName);

                    using (FileStream fs = System.IO.File.Create(path))
                    {
                        file.CopyTo(fs);
                        fs.Flush();
                    }

                    incidentReport.PhotoUrl.Add(Path.Combine("~/images/incident_images", fileName));
                }

                ViewBag.PhotoSelected = true;
                return(View(incidentReport));

            case "Next":
                if (!ModelState.IsValid)
                {
                    return(View(incidentReport));
                }

                if (incidentReport.PhotoUrl != null)
                {
                    ViewBag.Images        = incidentReport.PhotoUrl.Count;
                    ViewBag.UploadEnabled = incidentReport.PhotoUrl.Count > 0;
                }
                else
                {
                    ViewBag.Images        = 0;
                    ViewBag.UploadEnabled = false;
                }

                return(View("IncidentReport", incidentReport));

            default:
                return(View());
            }
        }