public async Task <IActionResult> AssignReportToInvestigation(InvestigationViewModel model) { //1. create new investigation if (ModelState.IsValid) { var newInvestigation = new Investigation() { //note, since an investigation can only have one report from report the status can be taken ReportId = model.ReportId, InvestigationDescription = model.InvestigationDescription, InvestigatorId = model.InvestigatorId }; _investigationService.CreateInvestigation(newInvestigation); var alterRep = _reportService.GetReportById(model.ReportId); alterRep.ReportStatus = model.InvestigationStatus; alterRep.ReportInvestigatorId = model.InvestigatorId; await _reportService.EditReport(alterRep); var user = await _userManager.GetUserAsync(HttpContext.User); var reporter = await _userManager.FindByIdAsync(alterRep.ReportReporterId); var reporterEmail = _userService.GetUserEmail(reporter); _emailService.SendEmail(reporter.Email, alterRep.ReportTitle + ", is assigned to a new investigation", user.UserName + EmailBodyContent.AssignInvestigationToReport + alterRep.ReportTitle); return(RedirectToAction("Index")); } //2. if 1==success - alter the report (I) change status (II) add investigatorid to report //----???---- shall we add investigaion id to report? n/y? return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int id, [Bind("Id, ReportId, ReportStatus, Description, ActionTakenOn")] InvestigationViewModel editInvestigation) { try { if (id != editInvestigation.Id) { return(NotFound()); } // Gets old investigation (for use later) var oldInvestigation = _investigationRepository.GetInvestigationtById(id); if (oldInvestigation != null) { var user = await _userManager.GetUserAsync(User); // Checks that current signed in user owns the investigation if (oldInvestigation.Investigator.Id == user.Id) { // Checks that model is valid if (ModelState.IsValid) { // Fetches report and sets the new status Report report = _reportRepository.GetReportById(editInvestigation.ReportId); report.Status = editInvestigation.ReportStatus; Investigation updatedInvestigation = new Investigation() { Id = editInvestigation.Id, Report = _reportRepository.GetReportById(editInvestigation.ReportId), DescriptionOfInvestigation = editInvestigation.Description, InvestigatedOn = oldInvestigation.InvestigatedOn, DateOfAction = editInvestigation.ActionTakenOn, Investigator = await _userManager.GetUserAsync(User) }; // Update the investigation with the new details _investigationRepository.UpdateInvestigation(updatedInvestigation); return(RedirectToAction("ViewReports", "Report")); } else { return(View(editInvestigation)); } } else { return(Unauthorized()); } } else { return(NotFound()); } } catch (Exception e) { _logger.LogError(e.Message); return(View("Error")); } }
public IActionResult CreateInvestigation(int id) { InvestigationViewModel model = new InvestigationViewModel() { ReportId = id }; return(View(model)); }
public IActionResult Create() { var model = new InvestigationViewModel { RepublicStates = combosHelper.GetComboRepublicStates(), ProyectTypes = combosHelper.GetComboProyectTypes() }; return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync(int reportId) { var user = await _userManager.GetUserAsync(HttpContext.User); var report = _reportService.GetReportById(reportId); var investigation = new InvestigationViewModel() { ReportId = report.ReportId, ReportTitle = report.ReportTitle, InvestigatorId = user.Id, InvestigatorName = user.UserName, InvestigatorEmail = user.Email, }; return(View(investigation)); }
public async Task <IActionResult> Create(InvestigationViewModel model) { if (ModelState.IsValid) { var invastigation = new Investigation { Name = model.Name, Description = model.Description, ProyectType = await dataContext.ProyectTypes.FirstOrDefaultAsync(m => m.Id == model.ProyectTypeId), RepublicState = await dataContext.RepublicStates.FirstOrDefaultAsync(m => m.Id == model.RepublicStateId), }; dataContext.Investigations.Add(invastigation); await dataContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public ActionResult GetInvestigations() { using (MTCDbContext db = new MTCDbContext()) { var beats = this.GetBeatList(); var contractors = this.GetContractorList(); var drivers = this.GetDriverList(); var chpOfficers = this.GetCHPOfficerList(); var rawData = db.Investigations.OrderBy(p => p.Date).ToList(); var data = new List <InvestigationViewModel>(); foreach (var rawItem in rawData) { try { InvestigationViewModel model = new InvestigationViewModel(); model.Id = rawItem.Id; model.Date = rawItem.Date; model.BeatId = rawItem.BeatId; model.BeatNumber = rawItem.BeatId != null?beats.FirstOrDefault(b => b.BeatId == rawItem.BeatId).BeatNumber : String.Empty; model.ContractorId = rawItem.ContractorId; model.ContractCompanyName = rawItem.ContractorId != null?contractors.FirstOrDefault(b => b.ContractorId == rawItem.ContractorId).ContractorCompanyName : String.Empty; model.DriverId = rawItem.DriverId; model.DriverName = rawItem.DriverId != null?drivers.FirstOrDefault(b => b.DriverId == rawItem.DriverId).DriverFullName : String.Empty; model.ViolationTypeId = rawItem.ViolationTypeId; model.ViolationTypeName = rawItem.ViolationType.Name; model.Summary = rawItem.Summary; model.CHPOfficerId = rawItem.CHPOfficerId; model.InvestigatingOfficer = rawItem.CHPOfficerId != null?chpOfficers.FirstOrDefault(b => b.Id == rawItem.CHPOfficerId).OfficeFullName : String.Empty; data.Add(model); } catch { } } return(Json(data.ToList(), JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> CreateInvestigation(int id, [Bind("ReportId, ReportStatus,Description,ActionTakenOn")] InvestigationViewModel newInvestigation) { try { if (ModelState.IsValid) { if (_investigationRepository.GetInvestigationtByReportId(newInvestigation.ReportId) == null) { // Fetch report and set its status Report report = _reportRepository.GetReportById(newInvestigation.ReportId); report.Status = newInvestigation.ReportStatus; // Create the Investigation Object Investigation investigation = new Investigation() { Report = report, DescriptionOfInvestigation = newInvestigation.Description, InvestigatedOn = DateTime.Now, DateOfAction = newInvestigation.ActionTakenOn, Investigator = await _userManager.GetUserAsync(User) }; _logger.LogInformation("Investigator:" + User.Identity.Name + ", added an investigation"); _investigationRepository.AddInvestigation(investigation); return(RedirectToAction("ViewReports", "Report")); } else { return(NotFound()); } } else { return(View(newInvestigation)); } } catch (Exception e) { _logger.LogError(e.Message); return(View("Error")); } }
public async Task <IViewComponentResult> InvokeAsync(int investigationId) { var user = await _userManager.GetUserAsync(HttpContext.User); var tempInv = _investigationService.GetInvestigationById(investigationId); var report = _reportService.GetReportById(tempInv.ReportId); var investigation = new InvestigationViewModel() { ReportId = report.ReportId, InvestigationId = tempInv.InvestigationId, ReportTitle = report.ReportTitle, InvestigatorId = user.Id, InvestigatorName = user.UserName, InvestigatorEmail = user.Email, InvestigationDescription = tempInv.InvestigationDescription, InvestigationStatus = report.ReportStatus }; return(View(investigation)); }
public async Task <IActionResult> Edit(int id) { try { var investigation = _investigationRepository.GetInvestigationtById(id); if (investigation != null) { var user = await _userManager.GetUserAsync(User); // Checks if current user owns the investigation if (investigation.Investigator.Id == user.Id) { InvestigationViewModel model = new InvestigationViewModel() { Id = investigation.Id, ReportId = investigation.Report.Id, ReportStatus = investigation.Report.Status, Description = investigation.DescriptionOfInvestigation, ActionTakenOn = investigation.DateOfAction }; return(View(model)); } else { return(Unauthorized()); } } else { return(NotFound()); } } catch (Exception e) { _logger.LogError(e.Message); return(View("Error")); } }
public ActionResult SaveInvestigation(InvestigationViewModel model) { using (MTCDbContext db = new MTCDbContext()) { Investigation investigation = null; bool isNew = false; if (model.Id > 0) { investigation = db.Investigations.Find(model.Id); } else { investigation = new Investigation(); investigation.CreatedOn = DateTime.Now; investigation.CreatedBy = HttpContext.User.Identity.Name; isNew = true; } investigation.Date = model.Date; investigation.DriverId = model.DriverId; investigation.BeatId = model.BeatId; investigation.ContractorId = model.ContractorId; investigation.CHPOfficerId = model.CHPOfficerId; investigation.Summary = model.Summary; investigation.ViolationTypeId = model.ViolationTypeId; investigation.ModifiedOn = DateTime.Now; investigation.ModifiedBy = HttpContext.User.Identity.Name; if (isNew) { db.Investigations.Add(investigation); } db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> EditInvestigation(InvestigationViewModel model) { if (ModelState.IsValid) { var newInvestigation = new Investigation() { InvestigationId = model.InvestigationId, ReportId = model.ReportId, InvestigationDescription = model.InvestigationDescription, InvestigatorId = model.InvestigatorId, }; _investigationService.UpdateInvestigation(newInvestigation); var alterRep = _reportService.GetReportById(model.ReportId); alterRep.ReportStatus = model.InvestigationStatus; //alterRep.ReportInvestigatorId = model.InvestigatorId; await _reportService.EditReport(alterRep); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }