public virtual ActionResult CreateBatch(CreateBatchViewModel model)
        {
            LogI("CreateBatch begin, orderIds=" + model.OrderIds + ", batchName=" + model.BatchName);

            var result = OrderBatchViewModel.CreateBatch(Db,
                                                         BatchManager,
                                                         model.OrderIds,
                                                         model.BatchName,
                                                         Time.GetAppNowTime(),
                                                         AccessManager.UserId);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public virtual ActionResult CheckAddOrdersToBatch(CreateBatchViewModel model)
        {
            LogI("CheckAddOrdersToBatch begin, orderIds=" + model.OrderIds + ", batchId=" + model.BatchId);

            var result = OrderBatchViewModel.CheckAddOrdersToBatch(Db,
                                                                   model.OrderIds);

            return(new JsonResult
            {
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public virtual ActionResult AddOrdersToBatch(CreateBatchViewModel model)
        {
            LogI("CreateBatch begin, orderIds=" + model.OrderIds + ", batchId=" + model.BatchId);

            var result = OrderBatchViewModel.AddOrdersToBatch(Db,
                                                              OrderHistoryService,
                                                              model.BatchId,
                                                              model.OrderIds,
                                                              Time.GetAppNowTime(),
                                                              AccessManager.UserId);

            return(new JsonResult
            {
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #4
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 #5
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));
        }