Example #1
0
        public async Task <IActionResult> Index()
        {
            DashboardViewModel _model = new DashboardViewModel();

            using RDATContext context = new RDATContext();
            List <TestingLog> activeLogs = context.TestingLogs.Where(tl => Convert.ToInt32(tl.Reported_Results) < 1).ToList();

            char[] goodResults = { '1', '2', '3' };

            // Get User Roles
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            bool IsAdmin    = currentUser.IsInRole("Admin");
            bool IsReadOnly = currentUser.IsInRole("ReadOnly");

            _model.BadgeTotalActiveDrivers     = context.Drivers.Where(d => d.TerminationDate == null && !d.isDelete).Count();
            _model.BadgeTotalActiveCompanies   = context.Companys.Where(c => c.Status == "1" && c.isDelete != true).Count(); // context.Companys.Where(d => ??).Count();
            _model.BadgeOutstandingDrugTest    = activeLogs.Where(tl => tl.Test_Type == "Drug").Count();
            _model.BadgeOutstandingAlcoholTest = activeLogs.Where(tl => tl.Test_Type == "Alcohol").Count();

            _model.FavoriteCompanies = context.Companys.Where(c => c.isFavorite).OrderByDescending(p => p.Id).ToList();

            _model.FavoriteDrivers = context.Drivers.Where(d => d.isFavorite).OrderByDescending(p => p.Id).ToList();



            return(View(_model));
        }
Example #2
0
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try
            {
                using RDATContext context = new RDATContext();

                Company _company = context.Companys.Where(c => c.Id == id).FirstOrDefault();

                _company.Name               = collection["Company.Name"];
                _company.Phone              = collection["Company.Phone"];
                _company.Fax                = collection["Company.Fax"];
                _company.AddressLine1       = collection["Company.AddressLine1"];
                _company.AddressLine2       = collection["Company.AddressLine2"];
                _company.City               = collection["Company.City"];
                _company.State              = collection["Company.State"];
                _company.Zip                = collection["Company.Zip"];
                _company.Email              = collection["Company.Email"];
                _company.Dot                = collection["Company.Dot"];
                _company.RepresentativeName = collection["Company.RepresentativeName"];
                _company.Status             = collection["Company.Status"];

                _company.Modified = DateTime.Now;

                context.Update(_company);
                context.SaveChanges();

                // return data;
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #3
0
        private bool BuildBatch(int id)
        {
            using (RDATContext context = new RDATContext())
            {
                List <TempTestingLog> _logs = context.TempTestingLogs.ToList();

                foreach (TempTestingLog log in _logs)
                {
                    TestingLog _testingLog = new TestingLog();
                    _testingLog.Test_Type            = log.Test_Type;
                    _testingLog.Driver_Id            = log.Driver_Id;
                    _testingLog.Driver_Name          = log.Driver_Name;
                    _testingLog.Created              = log.CreatedDate;
                    _testingLog.Selectiondatealcohol = log.CreatedDate;
                    _testingLog.Selectiondatedrug    = log.CreatedDate;
                    _testingLog.Modified             = log.ModifiedDate;
                    _testingLog.TestDate             = log.CreatedDate;
                    _testingLog.Batch_Id             = id;
                    _testingLog.Company_Id           = log.Company_Id;
                    _testingLog.Reported_Results     = "0";

                    context.TestingLogs.Add(_testingLog);
                }

                context.SaveChanges();
                return(true);
            }

            return(false);
        }
Example #4
0
        public IViewComponentResult Invoke(string searchTerm)
        {
            FeaturedCompaniesViewModel _model = new FeaturedCompaniesViewModel();

            using RDATContext context = new RDATContext();

            var my = searchTerm;

            try
            {
                if (searchTerm != null)
                {
                    _model.Companies = context.Companys.Where(c => c.Name.Contains(searchTerm)).OrderByDescending(p => p.Id).ToList();
                }
                else
                {
                    _model.Companies = context.Companys.Where(c => c.isFavorite).OrderByDescending(p => p.Id).ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }


            return(View(_model));
        }
Example #5
0
        public IActionResult Renewal(RenewalReportViewModel model)
        {
            RenewalReportViewModel _model = new RenewalReportViewModel();


            using RDATContext context = new RDATContext();
            List <Company> _co     = context.Companys.ToList();
            List <Driver>  drivers = new List <Driver>();

            _model.RenewalMonth = model.RenewalMonth;

            drivers = context.Drivers.Where(c => c.TerminationDate == null && c.EnrollmentDate.Value.Month == model.RenewalMonth).ToList();

            var driverList = drivers.Join(_co,
                                          d => d.Company_id,
                                          co => co.Id,
                                          (driver, company) => new DriverCompanyModel
            {
                Id              = driver.Id,
                DriverName      = driver.DriverName,
                CompanyName     = company.Name,
                Phone           = driver.Phone,
                Email           = driver.Email,
                EnrollmentDate  = driver.EnrollmentDate,
                TerminationDate = driver.TerminationDate,
                isFavorite      = driver.isFavorite,
            }).OrderBy(d => d.DriverName).ToList();

            _model.Drivers = driverList;

            return(View(_model));
        }
Example #6
0
        public ActionResult GetResults(string currentResult)
        {
            //Allowed response content format
            //{'E':'Letter E','F':'Letter F','G':'Letter G', 'selected':'F'}
            //"{'3':'Excused','2':'Negative','1':'Positive','4':'Undefined','selected': '4'}"
            int selectedResult = 0;

            if (currentResult == null)
            {
                currentResult = "Undefined";
            }

            StringBuilder sb = new StringBuilder();

            using (RDATContext context = new RDATContext())
            {
                var results = context.Results.OrderBy(a => a.DisplayName).ToList();
                foreach (var item in results)
                {
                    sb.Append(string.Format("'{0}':'{1}',", item.Id, item.DisplayName));
                }

                selectedResult = context.Results.Where(a => a.DisplayName == currentResult).First().Id;
            }

            sb.Append(string.Format("'selected':'{0}'", selectedResult));
            //var _json = JsonConvert.SerializeObject("{" + sb.ToString() + "}");
            //return Json(_json);
            return(Content("{" + sb.ToString() + "}"));
        }
Example #7
0
        public async Task <IActionResult> Create(
            [Bind("Company_id,DriverName,SSN,AddressLine1,AddressLine2,City,State,Zipcode,Location,Phone,Fax,Cell,Email,CDL")] Driver driver)
        {
            using RDATContext context = new RDATContext();
            var drivers = context.Drivers;

            try
            {
                if (ModelState.IsValid)
                {
                    driver.UniqueId       = Guid.NewGuid();
                    driver.EnrollmentDate = DateTime.Now;
                    drivers.Add(driver);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View());
        }
Example #8
0
        public ActionResult Create()
        {
            CreateDriverViewModel _model = new CreateDriverViewModel();
            Driver _driver = new Driver();

            _model.Driver = _driver;


            using RDATContext context = new RDATContext();
            List <SelectListItem> companies = context.Companys.Where(c => c.Status == "1").OrderBy(c => c.Name).Select(a =>
                                                                                                                       new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.Name
            }).ToList();

            _model.Companies = companies;

            List <SelectListItem> states = context.States.OrderBy(s => s.StateName).Select(a =>
                                                                                           new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.StateName
            }).ToList();

            _model.States = states;

            return(View(_model));
        }
Example #9
0
        public ActionResult UpdateDriver([FromBody] UpdateDriverResults results)
        {
            using RDATContext context = new RDATContext();

            // Check for Drug Update
            //if (results != null && results.Drug_TestingLogID != 0)
            //{
            //    TestingLog _drugResults = context.TestingLogs.Where(tl => tl.Id == results.Drug_TestingLogID).FirstOrDefault();
            //    _drugResults.ResultsDate = results.Drug_Results_Date;
            //    _drugResults.Reported_Results = results.Drug_Reported_Result;
            //    context.Update(_drugResults);
            //    context.SaveChanges();
            //}

            // Check for Alcohol
            //if (results != null && results.Alcohol_TestingLogID != 0)
            //{
            //    TestingLog _alcoholResults = context.TestingLogs.Where(tl => tl.Id == results.Alcohol_TestingLogID).FirstOrDefault();
            //    _alcoholResults.ResultsDate = results.Alcohol_Results_Date;
            //    _alcoholResults.Reported_Results = results.Alcohol_Reported_Result;
            //    context.Update(_alcoholResults);
            //    context.SaveChanges();
            //}

            if (results == null)
            {
                //  Send "false"
                return(Json(new { success = false, responseText = "The attached file is not supported." }));
            }
            else
            {
                //  Send "Success"
                return(Json(new { success = true, responseText = "Your message successfuly sent!" }));
            }
        }
Example #10
0
        public IActionResult Edit(int id)
        {
            using RDATContext context = new RDATContext();

            CreateDriverViewModel _model = new CreateDriverViewModel();

            // Get User Roles
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            _model.IsReadOnly = currentUser.IsInRole("ReadOnly");

            Driver _driver = context.Drivers.Where(d => d.Id == id).FirstOrDefault();

            ViewBag.CompanyName = _driver.DriverName;

            List <SelectListItem> states = context.States.OrderBy(s => s.StateName).Select(a =>
                                                                                           new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.StateName
            }).ToList();

            _model.States = states;

            _model.Driver = _driver;

            return(View(_model));
        }
Example #11
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                Company _company = new Company();

                // Add Company
                _company.Name         = collection["Company.Name"];
                _company.Phone        = collection["Company.Phone"];
                _company.Fax          = collection["Company.Fax"];
                _company.AddressLine1 = collection["Company.AddressLine1"];
                _company.AddressLine2 = collection["Company.AddressLine2"];
                _company.City         = collection["Company.City"];
                _company.State        = collection["Company.Zip"];
                _company.Zip          = collection["Company.AddressLine1"];
                _company.Email        = collection["Company.Email"];

                _company.Created  = DateTime.Now;
                _company.Modified = DateTime.Now;
                _company.isDelete = false;
                _company.Status   = "1";

                using RDATContext context = new RDATContext();

                context.Companys.Add(_company);
                context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #12
0
        public ActionResult GetDriverLogs(int id)
        {
            SingleBatchViewModel _model = new SingleBatchViewModel();

            using (RDATContext context = new RDATContext())
            {
                // List<TestingLog> _logs = context.TestingLogs.Where(tl => tl.Batch_Id == BatchId).ToList();
                List <BatchCompanyModel> _logs = (from tl in context.TestingLogs
                                                  join c in context.Companys on tl.Company_Id equals c.Id
                                                  join b in context.Batches on tl.Batch_Id equals b.Id
                                                  select new BatchCompanyModel()
                {
                    Id = tl.Id,
                    Driver_Id = tl.Driver_Id,
                    Driver_Name = tl.Driver_Name,
                    Company_Id = tl.Company_Id,
                    Company_Name = c.Name,
                    Reported_Results = tl.Reported_Results,
                    ResultsDate = tl.ResultsDate,
                    Batch_Id = tl.Batch_Id,
                    BatchDate = b.RunDate,
                    ClosedDate = tl.ClosedDate,
                    Test_Type = tl.Test_Type
                }).Where(tl => tl.Driver_Id == id).ToList();

                foreach (BatchCompanyModel l in _logs)
                {
                    l.Reported_Results = l.Reported_Results == "1" ? "Positive" : l.Reported_Results == "2" ? "Negative" : l.Reported_Results == "3" ? "Excused" : " ";
                }

                _model.TestingLogs = _logs;
            }

            return(View(_model));
        }
Example #13
0
        public ActionResult DashboardCompanies()
        {
            using RDATContext context = new RDATContext();

            var companys = context.Companys.OrderByDescending(p => p.Id).Take(5);

            return(View(companys.ToList()));
        }
Example #14
0
        // GET: Company
        public ActionResult Index(string[] args)
        {
            using RDATContext context = new RDATContext();

            var companys = context.Companys;

            return(View(companys.ToList()));
        }
Example #15
0
        public ActionResult Edit(int id, IFormCollection collection)
        {
            CreateDriverViewModel _model = new CreateDriverViewModel();
            Driver _driver = new Driver();

            try
            {
                using RDATContext context = new RDATContext();

                _driver = context.Drivers.Where(d => d.Id == id).FirstOrDefault();

                _driver.DriverName   = collection["Driver.DriverName"];
                _driver.Phone        = collection["Driver.Phone"];
                _driver.Fax          = collection["Driver.Fax"];
                _driver.AddressLine1 = collection["Driver.AddressLine1"];
                _driver.AddressLine2 = collection["Driver.AddressLine2"];
                _driver.City         = collection["Driver.City"];
                _driver.State        = collection["Driver.State"];
                _driver.Zipcode      = collection["Driver.Zipcode"];
                _driver.Email        = collection["Driver.Email"];
                _driver.CDL          = collection["Driver.CDL"];
                _driver.Cell         = collection["Driver.Cell"];

                if (Int32.TryParse(collection["Driver.Company_id"], out int result))
                {
                    _driver.Company_id = Int32.Parse(collection["Driver.Company_id"]);
                }
                ;


                _driver.EnrollmentDate = DateTime.Parse(collection["Driver.EnrollmentDate"]);

                if (DateTime.TryParse(collection["Driver.TerminationDate"], out DateTime resultDate))
                {
                    _driver.TerminationDate = DateTime.Parse(collection["Driver.TerminationDate"]);
                }

                context.Update(_driver);
                context.SaveChanges();

                // return data;
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                using RDATContext context = new RDATContext();
                List <SelectListItem> states = context.States.OrderBy(s => s.StateName).Select(a =>
                                                                                               new SelectListItem
                {
                    Value = a.Id.ToString(),
                    Text  = a.StateName
                }).ToList();
                _model.States = states;

                _model.Driver = _driver;
                return(View(_model));
            }
        }
Example #16
0
        public IActionResult Search(string driverName, string company, string cdl)
        {
            using RDATContext context = new RDATContext();
            DriverSearchModel _model  = new DriverSearchModel();
            List <Driver>     drivers = new List <Driver>();

            if (driverName != "")
            {
                drivers = context.Drivers.Where(c => c.DriverName.Contains(driverName)).ToList();
            }

            if (!company.IsEmpty() && company != null)
            {
                List <Company> cos = context.Companys.Where(c => c.Name.Contains(company)).ToList();

                foreach (Company co in cos)
                {
                    List <Driver> cosDrivers = context.Drivers.Where(d => d.Company_id == co.Id).ToList();
                    if (cosDrivers != null)
                    {
                        drivers.AddRange(cosDrivers);
                    }
                }
            }

            if (!cdl.IsEmpty() && cdl != null)
            {
                List <Driver> cdlDrivers = drivers.Where(c => c.CDL.Contains(cdl)).ToList();
                if (cdlDrivers != null)
                {
                    drivers.AddRange(cdlDrivers);
                }
            }

            List <Company> _co        = context.Companys.ToList();
            var            driverList = drivers.Join(_co,
                                                     d => d.Company_id,
                                                     co => co.Id,
                                                     (driver, company) => new DriverCompanyModel
            {
                Id              = driver.Id,
                DriverName      = driver.DriverName,
                CompanyName     = company.Name,
                Phone           = driver.Phone,
                Email           = driver.Email,
                EnrollmentDate  = driver.EnrollmentDate,
                TerminationDate = driver.TerminationDate,
                isFavorite      = driver.isFavorite,
            }).ToList();

            var count = drivers.Count();

            _model.Drivers    = driverList;
            _model.DriverName = driverName;

            return(View("Index", _model));
        }
Example #17
0
        // Show All Batches
        public IActionResult ViewBatch()
        {
            ViewBatchViewModel _model = new ViewBatchViewModel();

            using (RDATContext context = new RDATContext())
            {
                _model.Batches = context.Batches.OrderByDescending(o => o.Id).ToList();
            }

            return(View(_model));
        }
Example #18
0
        public List <SelectListItem> GetCompanies()
        {
            using RDATContext context = new RDATContext();
            List <SelectListItem> companies = context.Companys.Where(c => c.isDelete == false).OrderBy(c => c.Name).Select(a =>
                                                                                                                           new SelectListItem
            {
                Value = a.Name,                       //a.Id.ToString(),
                Text  = a.Name
            }).ToList();

            return(companies);
        }
Example #19
0
        public IViewComponentResult Invoke(string searchTerm)
        {
            FeaturedDriversViewModel  _model   = new FeaturedDriversViewModel();
            List <Driver>             _drivers = new List <Driver>();
            List <DriverSearchResult> _results = new List <DriverSearchResult>();

            using RDATContext context = new RDATContext();

            var my = searchTerm;

            if (searchTerm != null)
            {
                _drivers = context.Drivers.Where(d => d.DriverName.Contains(searchTerm)).OrderByDescending(p => p.Id).ToList();
            }
            else
            {
                _drivers = context.Drivers.Where(d => d.isFavorite).OrderByDescending(p => p.Id).ToList();
            }

            foreach (Driver d in _drivers)
            {
                string _companyName = context.Companys.Where(c => c.Id == d.Company_id).FirstOrDefault().Name;

                // Get latest batch - 0 is no batches exist
                int _latestBatchId = context.Batches.OrderByDescending(b => b.Id).FirstOrDefault() != null?context.Batches.OrderByDescending(b => b.Id).FirstOrDefault().Id  : 0;

                // Determine if the Driver was in the last batch - check for 0 first
                bool _isInLatestBatch = _latestBatchId != 0 ? context.TestingLogs.Where(l => l.Batch_Id == _latestBatchId).Any(tl => tl.Driver_Id == d.Id && tl.Batch_Id == _latestBatchId) : false;

                // Look in any batch
                bool _isInAnyBatch = context.TestingLogs.Where(tl => tl.Driver_Id == d.Id && tl.ResultsDate == null).Count() > 0 ? true : false;


                _results.Add(new DriverSearchResult
                {
                    CompanyName     = _companyName,
                    DriverName      = d.DriverName,
                    TerminationDate = d.TerminationDate,
                    EnrollmentDate  = d.EnrollmentDate,
                    Id            = d.Id,
                    isLatestBatch = _isInAnyBatch, // _isInLatestBatch,
                    isFavorite    = d.isFavorite
                });
            }

            _model.Drivers = _results;

            return(View(_model));
        }
Example #20
0
        public IActionResult Dashboard()
        {
            DashboardViewModel _model = new DashboardViewModel();

            using RDATContext context = new RDATContext();

            _model.BadgeTotalActiveDrivers     = context.Drivers.Count();
            _model.BadgeTotalActiveCompanies   = 77; // context.Companys.Where(d => ??).Count();
            _model.BadgeOutstandingDrugTest    = 99;
            _model.BadgeOutstandingAlcoholTest = 88;

            var companys = context.Companys.OrderByDescending(p => p.Id).Take(5);

            return(View(_model));
        }
Example #21
0
        public ActionResult Favorite(int id)
        {
            var thisID = id;

            using RDATContext context = new RDATContext();

            Company _company = context.Companys.Where(c => c.Id == id).FirstOrDefault();

            _company.isFavorite = !_company.isFavorite;

            context.Update(_company);
            context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
Example #22
0
        // GET: Company/List
        public ActionResult List(int id)
        {
            using RDATContext context = new RDATContext();

            var companys = context.Companys;

            var count = companys.Count();

            var tempList = new List <Company>();
            var co1      = new Company();

            co1.Name = "Chris";
            tempList.Add(co1);

            return(View(tempList));
        }
Example #23
0
        private bool ClearTempBatch()
        {
            try
            {
                using (RDATContext context = new RDATContext())
                {
                    List <TempTestingLog> existingEntries = context.TempTestingLogs.ToList();
                    context.TempTestingLogs.RemoveRange(existingEntries);
                    context.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #24
0
        public IActionResult UpdateBatch(CreateBatchViewModel model)
        {
            // Create Batch

            Batch _batch          = new Batch();
            var   _tempTestingLog = new List <TempTestingLog>();

            using (RDATContext context = new RDATContext())
            {
                // get list of existing test logs
                _tempTestingLog = context.TempTestingLogs.ToList();
                // get active drivers
                int   activeDrivers   = context.Drivers.Where(d => d.TerminationDate == null && !d.isDelete).Count();
                int   numDrug         = context.TempTestingLogs.Where(t => t.Test_Type == "Drug").Count();
                int   numAlcohol      = context.TempTestingLogs.Where(t => t.Test_Type == "Alcohol").Count();
                float _percentDrug    = ((float)numDrug / activeDrivers) * 100;
                float _percentAlcohol = ((float)numAlcohol / activeDrivers) * 100;
                ViewBag.percentDrug    = _percentDrug.ToString("##");
                ViewBag.percentAlcohol = _percentAlcohol.ToString("##");
                ViewBag.totalDrivers   = numDrug + numAlcohol;
                ViewBag.activeDrivers  = activeDrivers;

                // Create the Batch
                _batch.Created            = DateTime.Now;
                _batch.RunDate            = DateTime.Now;
                _batch.Alcohol_Percentage = (int)Math.Round(_percentAlcohol);
                _batch.Drug_Percentage    = (int)Math.Round(_percentDrug);
                _batch.Alcohol_Tests      = numAlcohol;
                _batch.Drug_Tests         = numDrug;
                _batch.Eligible_Drivers   = activeDrivers;

                context.Batches.Add(_batch);
                context.SaveChanges();

                // Get New Batch ID
                int batchID = _batch.Id;
                // Build Batch
                BuildBatch(batchID);
                ClearTempBatch();
            }

            return(RedirectToAction("ViewBatch", "Reports"));
        }
Example #25
0
        public JsonResult GetCompanies()
        {
            using RDATContext context = new RDATContext();

            var    companys = context.Companys;
            string json     = JsonConvert.SerializeObject(companys);

            var count = companys.Count();

            var w = new GridData()
            {
                data = json, itemsCount = count
            };

            string data = JsonConvert.SerializeObject(w);

            // return data;
            return(Json(json));
        }
Example #26
0
        public IActionResult GetActiveDriversByCompany(int companyId)
        {
            using RDATContext context = new RDATContext();

            var    activeDrivers = context.Drivers.Where(d => d.TerminationDate == null && d.Company_id == companyId);
            string json          = JsonConvert.SerializeObject(activeDrivers);

            var count = activeDrivers.Count();

            var w = new GridData()
            {
                data = json, itemsCount = count
            };

            string data = JsonConvert.SerializeObject(w);

            // return data;
            return(View(json));
        }
Example #27
0
        public ActionResult Create()
        {
            CreateCompanyViewModel _model = new CreateCompanyViewModel();
            Company _company = new Company();

            _model.Company = _company;

            using RDATContext context = new RDATContext();

            List <SelectListItem> states = context.States.OrderBy(s => s.StateName).Select(a =>
                                                                                           new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.StateName
            }).ToList();

            _model.States = states;

            return(View(_model));
        }
Example #28
0
        public ActionResult Edit(int id)
        {
            using RDATContext context = new RDATContext();

            CreateCompanyViewModel _model = new CreateCompanyViewModel();

            Company _company = context.Companys.Where(c => c.Id == id).FirstOrDefault();

            ViewBag.CompanyName = _company.Name;

            List <SelectListItem> states = context.States.OrderBy(s => s.StateName).Select(a =>
                                                                                           new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.StateName
            }).ToList();

            _model.States = states;

            _model.Company = _company;
            // return data;
            return(View(_model));
        }
Example #29
0
        public ActionResult Favorite(int id)
        {
            var thisID = id;

            using RDATContext context = new RDATContext();

            try
            {
                Driver _driver = context.Drivers.Where(c => c.Id == id).FirstOrDefault();

                _driver.isFavorite = !_driver.isFavorite;

                context.Update(_driver);
                context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }


            return(RedirectToAction(nameof(Index)));
        }
Example #30
0
        public UpdateDriverResults GetDriver(int id)
        {
            var thisID = id;

            using RDATContext context = new RDATContext();
            UpdateDriverResults _driverResults = new UpdateDriverResults();

            Driver _driver  = context.Drivers.Where(c => c.Id == id).FirstOrDefault();
            int    _batchId = context.Batches.OrderByDescending(b => b.Id).FirstOrDefault().Id;

            // Get TestingLog
            // TODO: Create List of Alcohol Dates - There can be multiples
            List <TestingLog> _logDrug = context.TestingLogs.Where(l => l.Driver_Id == id && l.Test_Type == "Drug" && l.ResultsDate == null).ToList();

            // TODO: Create List of Alcohol Dates - There can be multiples
            List <TestingLog> _logAlcohol = context.TestingLogs.Where(l => l.Driver_Id == id && l.Test_Type == "Alcohol" && l.ResultsDate == null).ToList();

            // Set Values
            _driverResults.Driver_Id       = _driver.Id;
            _driverResults.Driver_Name     = _driver.DriverName;
            _driverResults.Company_Name    = context.Companys.Where(c => c.Id == _driver.Company_id).FirstOrDefault().Name;
            _driverResults.Driver_UniqueID = _driver.UniqueId.ToString();

            // Do we have results
            _driverResults.Alcohol_Show = _logAlcohol.Count > 0 ? true : false;
            _driverResults.Drug_Show    = _logDrug.Count > 0 ? true : false;

            // Alcohol Test
            if (_logAlcohol.Count > 0)
            {
                List <AlcoholResult> results = new List <AlcoholResult>();
                foreach (TestingLog tl in _logAlcohol)
                {
                    AlcoholResult alcoholResult = new AlcoholResult();
                    alcoholResult.Alcohol_TestingLogID    = tl.Id;
                    alcoholResult.Alcohol_Test_Date       = tl.TestDate;
                    alcoholResult.Alcohol_Specimen_Id     = tl.Specimen_Id;
                    alcoholResult.Alcohol_Results_Date    = tl.ResultsDate;
                    alcoholResult.Alcohol_Reported_Result = tl.Reported_Results;
                    alcoholResult.BatchID = tl.Batch_Id;
                    results.Add(alcoholResult);
                }

                _driverResults.AlcoholResults = results;
            }

            // Drug Test
            if (_logDrug.Count > 0)
            {
                List <DrugResult> dresults = new List <DrugResult>();
                foreach (TestingLog tl in _logDrug)
                {
                    DrugResult drugResult = new DrugResult();
                    drugResult.Drug_TestingLogID    = tl.Id;
                    drugResult.Drug_Test_Date       = tl.TestDate;
                    drugResult.Drug_Specimen_Id     = tl.Specimen_Id;
                    drugResult.Drug_Results_Date    = tl.ResultsDate;
                    drugResult.Drug_Reported_Result = tl.Reported_Results;
                    drugResult.BatchID = tl.Batch_Id;
                    dresults.Add(drugResult);
                }

                _driverResults.DrugResults = dresults;
            }

            return(_driverResults);
        }