示例#1
0
        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));
        }