public IActionResult ReportConfirm(int id) { if (HttpContext.Session.GetString("LoginID") == null) { return(RedirectToAction("Login", "Users")); } CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext; User user = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))); if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin")) { return(RedirectToAction("Error", "Admin")); } ServiceReport meh = context.getServiceReport(id); double totalmshremain = context.GetRemainingMSHByCompany(meh); if (totalmshremain < meh.MSHUsed) { TempData["error"] = "The company you are trying to confirm currently does not have enough remaining MSH."; return(RedirectToAction("Report", new { id })); } context.LogAction("Service Report", "Service Report (SRN: " + id + ") has been confirmed.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")))); context.ReportConfirm(id); ServiceReport remains = context.SubtractMSHUsingSR(context.getServiceReport(id)); while (remains.MSHUsed != 0) { remains = context.SubtractMSHUsingSR(remains); } Debug.WriteLine("hi id = " + id); return(RedirectToAction("ViewReports")); }
public IActionResult EditReport(ServiceReport report) { if (HttpContext.Session.GetString("LoginID") == null) { return(RedirectToAction("Login", "Users")); } List <SelectListItem> PurposeList = new List <SelectListItem>(); PurposeList.Add(new SelectListItem { Value = "Project", Text = "Project" }); PurposeList.Add(new SelectListItem { Value = "Installation", Text = "Installation" }); PurposeList.Add(new SelectListItem { Value = "M.S.A", Text = "M.S.A" }); PurposeList.Add(new SelectListItem { Value = "Chargable", Text = "Chargable" }); PurposeList.Add(new SelectListItem { Value = "P.O.C", Text = "P.O.C" }); PurposeList.Add(new SelectListItem { Value = "Delivery", Text = "Delivery" }); PurposeList.Add(new SelectListItem { Value = "Return", Text = "Return" }); PurposeList.Add(new SelectListItem { Value = "Others", Text = "Others" }); ViewData["Purpose"] = PurposeList; List <SelectListItem> JobStatusList = new List <SelectListItem>(); JobStatusList.Add(new SelectListItem { Value = "Completed", Text = "Completed" }); JobStatusList.Add(new SelectListItem { Value = "Followup Required", Text = "Followup Required" }); JobStatusList.Add(new SelectListItem { Value = "Recommendation Requied", Text = "Recommendation Required" }); JobStatusList.Add(new SelectListItem { Value = "Escalated to Ext. Support", Text = "Escalated to Ext. Support" }); ViewData["JobStatusList"] = JobStatusList; //update database CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext; User user = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))); if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin" || (user.FirstName + user.LastName) == context.getServiceReport(report.SerialNumber).ReportFrom)) { return(RedirectToAction("Login", "Users")); } if (!ModelState.IsValid) { return(View(report)); } if (ModelState.IsValid) { double totalmshremain = context.GetRemainingMSHByCompany(report); Debug.WriteLine("Debug from post editreport: Total MSH Remaining : " + totalmshremain); double calculatedhours = context.CalculateMSH(report.TimeStart, report.TimeEnd); //ModelState.AddModelError("", "The calculated MSH:" + calculatedhours); //return View(model); if (totalmshremain < calculatedhours) { ModelState.AddModelError("", "The company you have selected does not have enough remaining MSH, Please contact your Boss immediately regarding this issue."); return(View(report)); } if (report.TimeStart > DateTime.Now || report.TimeEnd > DateTime.Now) { ModelState.AddModelError("", "Please enter a report after the service is rendered"); return(View(report)); } if (!(report.TimeStart.CompareTo(report.TimeEnd) <= 0)) { ModelState.AddModelError("", "your start time should be before your end time"); return(View(report)); } context.ReportEdit(report); context.LogAction("Service Report", "Service Report (SRN: " + report.SerialNumber + ") has been edited.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")))); return(RedirectToAction("Report", new { id = report.SerialNumber })); } return(View(report)); }
public IActionResult AddNewReport(ServiceReport model) { if (HttpContext.Session.GetString("LoginID") == null) { return(RedirectToAction("Login", "Users")); } CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext; ViewData["Companies"] = context.GetClientByContract(); #region prepare for failure codes List <SelectListItem> PurposeList = new List <SelectListItem>(); PurposeList.Add(new SelectListItem { Value = "Project", Text = "Project" }); PurposeList.Add(new SelectListItem { Value = "Installation", Text = "Installation" }); PurposeList.Add(new SelectListItem { Value = "M.S.A", Text = "M.S.A" }); PurposeList.Add(new SelectListItem { Value = "Chargable", Text = "Chargable" }); PurposeList.Add(new SelectListItem { Value = "P.O.C", Text = "P.O.C" }); PurposeList.Add(new SelectListItem { Value = "Delivery", Text = "Delivery" }); PurposeList.Add(new SelectListItem { Value = "Return", Text = "Return" }); PurposeList.Add(new SelectListItem { Value = "Others", Text = "Others" }); ViewData["Purpose"] = PurposeList; List <SelectListItem> JobStatusList = new List <SelectListItem>(); JobStatusList.Add(new SelectListItem { Value = "Completed", Text = "Completed" }); JobStatusList.Add(new SelectListItem { Value = "Followup Required", Text = "Followup Required" }); JobStatusList.Add(new SelectListItem { Value = "Recommendation Requied", Text = "Recommendation Required" }); JobStatusList.Add(new SelectListItem { Value = "Escalated to Ext. Support", Text = "Escalated to Ext. Support" }); ViewData["JobStatusList"] = JobStatusList; model.SerialNumber = context.getReportCounts() + 1; string name = ""; if (((TempData.Peek("dataishere") != null).ToString().ToLower()) == "true") { name = TempData.Peek("dataishere").ToString(); } if (name != "") { ClientAddress cA = context.GetClientAddressList(name); List <string> aList = cA.Addresslist; List <SelectListItem> AddressList = new List <SelectListItem>(); if (aList != null) { for (int i = 0; i < aList.Count(); i++) { AddressList.Add(new SelectListItem { Value = aList[i], Text = aList[i] }); } } ViewData["AddressList"] = AddressList; } else { ModelState.AddModelError("", "A error occured. Important"); return(View(model)); } #endregion if (!ModelState.IsValid) { return(View(model)); } if (ModelState.IsValid) { double totalmshremain = context.GetRemainingMSHByCompany(model); double calculatedhours = context.CalculateMSH(model.TimeStart, model.TimeEnd); //for test purpose //ModelState.AddModelError("", "The calculated MSH:" + calculatedhours); //return View(model); if (totalmshremain < calculatedhours) { ModelState.AddModelError("", "The company you have selected does not have enough remaining MSH, Please contact your Boss immediately regarding this issue."); return(View(model)); } if (context.CheckExisitingReportID(model.SerialNumber)) { ModelState.AddModelError("", "Contact Application Developer"); return(View(model)); } if (model.TimeStart > DateTime.Now || model.TimeEnd > DateTime.Now) { ModelState.AddModelError("", "Please enter a report after the service is rendered"); return(View(model)); } if (!(model.TimeStart.CompareTo(model.TimeEnd) <= 0)) { ModelState.AddModelError("", "your start time should be before your end time"); return(View(model)); } User user = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))); model.ReportFrom = user.FirstName + user.LastName; context.AddServiceReport(model); context.LogAction("Service Report", "Service Report (SRN: " + model.SerialNumber + ") created for " + model.ClientCompanyName + " at " + model.ClientAddress + ".", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")))); TempData.Remove("dataishere"); return(RedirectToAction("ViewReports", "ServiceReport")); } return(View(model)); }