예제 #1
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);
        }
예제 #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());
            }
        }
예제 #3
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());
            }
        }
예제 #4
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));
            }
        }
예제 #5
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)));
        }
예제 #6
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);
            }
        }
예제 #7
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"));
        }
예제 #8
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)));
        }
예제 #9
0
        public ActionResult saveTestingLog(int id, string propertyName, string value)
        {
            var status  = false;
            var message = "";

            // Update data to database
            using (RDATContext context = new RDATContext())
            {
                var _log = context.TestingLogs.Find(id);

                object updateValue = value;
                bool   isValid     = true;

                if (propertyName == "Reported_Results")
                {
                    int newResultID = 0;
                    if (int.TryParse(value, out newResultID))
                    {
                        updateValue = newResultID;
                        //Update value field
                        value = context.Results.Where(a => a.Id == newResultID).First().DisplayName;
                    }
                    else
                    {
                        isValid = false;
                    }
                }
                else if (propertyName == "ResultsDate" || propertyName == "TestDate" || propertyName == "ClosedDate")
                {
                    DateTime mod;
                    if (DateTime.TryParseExact(value, "dd-MM-yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out mod))
                    {
                        updateValue = mod;
                    }
                    else
                    {
                        isValid = false;
                    }
                }

                if (_log != null && isValid)
                {
                    if (propertyName == "ResultsDate" || propertyName == "TestDate" || propertyName == "ClosedDate")
                    {
                        context.Entry(_log).Property(propertyName).CurrentValue = (DateTime)updateValue;
                    }
                    else if (propertyName == "Specimen_Id")
                    {
                        context.Entry(_log).Property(propertyName).CurrentValue = Convert.ToInt32(updateValue);
                    }
                    else
                    {
                        context.Entry(_log).Property(propertyName).CurrentValue = updateValue.ToString();
                    }
                    context.SaveChanges();
                    status = true;
                }
                else
                {
                    message = "Error!";
                }
            }

            var     response = new { value = value, status = status, message = message };
            JObject o        = JObject.FromObject(response);

            return(Content(o.ToString()));
        }
예제 #10
0
        public IActionResult CreateBatch(CreateBatch batchRequest)
        {
            CreateBatchViewModel _model = new CreateBatchViewModel();
            var driversDrug             = new List <Driver>();
            var driversAlcohol          = new List <Driver>();
            var _tempTestingLog         = new List <TempTestingLog>();

            // Determine whether
            if (batchRequest == null || batchRequest.AlcoholPercentage == 0 && batchRequest.DrugPercentage == 0)
            {
                // Load existing temp log entries
                using (RDATContext context = new RDATContext())
                {
                    // get list of existing test logs
                    _tempTestingLog = context.TempTestingLogs.ToList();
                    // get active drivers
                    //var activeDrivers = context.Drivers.Where(d => d.EnrollmentDate > d.TerminationDate).Count();
                    var   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;
                }
            }
            else
            {
                // generate new entries
                float  _percentDrug    = (float)batchRequest.DrugPercentage / 100;
                float  _percentAlcohol = (float)batchRequest.AlcoholPercentage / 100;
                double _percentage     = 0;
                ViewBag.percentDrug    = batchRequest.DrugPercentage;
                ViewBag.percentAlcohol = batchRequest.AlcoholPercentage;

                var activeDrivers = 0;

                using (RDATContext context = new RDATContext())
                {
                    List <TempTestingLog> existingEntries = context.TempTestingLogs.ToList();
                    // First get rid of old entries
                    context.TempTestingLogs.RemoveRange(existingEntries);

                    activeDrivers = context.Drivers.Where(d => d.TerminationDate == null && !d.isDelete).Count();

                    int numDrug    = (int)(_percentDrug * activeDrivers);
                    int numAlcohol = (int)(_percentAlcohol * activeDrivers);
                    // _percentage = (double)numDrug / activeDrivers;
                    // _percentage = _percentage * 100;
                    ViewBag.percentage    = _percentage.ToString("##.##");
                    ViewBag.activeDrivers = activeDrivers;
                    driversDrug           = context.Drivers.Where(d => d.TerminationDate == null && !d.isDelete).OrderBy(d => Guid.NewGuid()).Take(numDrug).ToList();
                    driversAlcohol        = context.Drivers.Where(d => d.TerminationDate == null && !d.isDelete).OrderBy(d => Guid.NewGuid()).Take(numAlcohol).ToList();

                    foreach (Driver d in driversDrug)
                    {
                        TempTestingLog _tempLog = new TempTestingLog();
                        _tempLog.Test_Type    = "Drug";
                        _tempLog.Driver_Id    = d.Id;
                        _tempLog.Driver_Name  = d.DriverName;
                        _tempLog.Company_Id   = d.Company_id;
                        _tempLog.CreatedDate  = DateTime.Now;
                        _tempLog.ModifiedDate = DateTime.Now;
                        // context.TempTestingLogs.Add(_tempLog);
                        _tempTestingLog.Add(_tempLog);
                    }

                    foreach (Driver d in driversAlcohol)
                    {
                        TempTestingLog _tempLog = new TempTestingLog();
                        _tempLog.Test_Type    = "Alcohol";
                        _tempLog.Driver_Id    = d.Id;
                        _tempLog.Driver_Name  = d.DriverName;
                        _tempLog.Company_Id   = d.Company_id;
                        _tempLog.CreatedDate  = DateTime.Now;
                        _tempLog.ModifiedDate = DateTime.Now;
                        // context.TempTestingLogs.Add(_tempLog);
                        _tempTestingLog.Add(_tempLog);
                    }

                    // Add new records to database


                    var count = _tempTestingLog.Count();
                    ViewBag.totalDrivers = count;

                    foreach (TempTestingLog log in _tempTestingLog)
                    {
                        context.TempTestingLogs.Add(log);
                    }
                    context.SaveChanges();
                };
            }


            _model.tempTestingLogs = _tempTestingLog;
            _model.batchRequest    = new CreateBatch();

            // Old model on page was --> IEnumerable<RDAT.Models.Driver>

            return(View(_model));
        }