예제 #1
0
        public virtual Model.Batch Create(CreateBatch batch)
        {
            var uriBuilder = this.GetRequestStringBuilder(string.Format(CreateBatchUrl, projectId));
            var response   = ExecutePostRequest(uriBuilder, batch, auth);

            return(JsonConvert.DeserializeObject <Model.Batch>(response["response"]["data"].ToString()));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,ActivePool,DrugPercentage,DrugTestDate,AlcoholPercentage,AlcoholTestDate")] CreateBatch createBatch)
        {
            if (id != createBatch.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(createBatch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CreateBatchExists(createBatch.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(createBatch));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("id,ActivePool,DrugPercentage,DrugTestDate,AlcoholPercentage,AlcoholTestDate")] CreateBatch createBatch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(createBatch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(createBatch));
        }
예제 #4
0
        public void TestInvalidCreate()
        {
            var createBatch = new CreateBatch
            {
                DefaultCarrierAccount    = "invalid_carrier_account",
                DefaultServicelevelToken = "invalid_servicelevel_token",
                LabelFiletype            = null,
                Metadata = ""
            };

            Assert.That(async() => await GetShippoClient().CreateBatch(createBatch), Throws.TypeOf <ShippoException>());
        }
예제 #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));
        }
예제 #6
0
        public async Task <Batch> CreateBatch(CreateBatch createBatch)
        {
            string ep = string.Format("{0}/batches", apiEndpoint);

            return(await this.apiClient.DoRequestAsync <Batch>(ep, HttpMethod.Post, Serialize(createBatch)));
        }