public async Task <ActionResult <BatchDto> > Post(CreateBatchDto dto) { if (dto == null) { return(BadRequest()); } BatchDto result = null; try { _logger.LogInformation($"{nameof(Post)} Started"); var repoObj = _mapper.Map <Batch>(dto); if (await _batchRepository.AddBatch(repoObj)) { result = _mapper.Map <BatchDto>(repoObj); return(CreatedAtRoute(nameof(GetBatch), new { id = result.BatchId }, result)); } } catch (Exception ex) { _logger.LogError(ex, nameof(Post), null); throw; } return(result); }
public async Task <BatchDto> GetBatch(int id) { Batch batch = await BatchDataProvider.GetBatch(id); BatchDto dto = new BatchDto() { Id = batch.Id, Beer = batch.Beer, BatchName = batch.BatchName, BatchNumber = batch.BatchNumber, Status = batch.Status, SubStatus = batch.SubStatus, Brewers = batch.Brewers, Recipe = batch.Recipe, Yeast = batch.Yeast, PreBoilGravity = batch.PreBoilGravity, OriginalGravity = batch.OriginalGravity, FinalGravity = batch.FinalGravity, ABV = batch.ABV, DateBrewed = batch.DateBrewed, DatePackaged = batch.DatePackaged, DateTapped = batch.DateTapped, BrewingNotes = batch.BrewingNotes, TastingNotes = batch.TastingNotes, Created = batch.Created, CreatedBy = batch.CreatedBy }; return(dto); }
/// <summary> /// Validates the data stored in the Dto being passed through from the Client side /// </summary> public bool ValidateRestData(BatchDto batch) { var context = new ValidationContext(batch); var results = new List <ValidationResult>(); return(Validator.TryValidateObject(batch, context, results)); }
internal static BatchRow MapToBatchRow(BatchDto pBatch) { if (pBatch == null) { return(null); } var _batchRow = new BatchRow(); _batchRow.Batch_id = pBatch.BatchId; _batchRow.InventoryStatus = pBatch.InventoryStatus; _batchRow.First_serial = pBatch.FirstSerial; _batchRow.Last_serial = pBatch.LastSerial; _batchRow.Request_id = pBatch.RequestId; if (pBatch.BoxId > 0) { _batchRow.Box_id = pBatch.BoxId; } if (pBatch.CustomerAcctId > 0) { _batchRow.Customer_acct_id = pBatch.CustomerAcctId; } return(_batchRow); }
public virtual BatchDto setRetries(SetJobRetriesDto setJobRetriesDto) { try { EnsureUtil.ensureNotNull("setJobRetriesDto", setJobRetriesDto); EnsureUtil.ensureNotNull("retries", setJobRetriesDto.Retries); } catch (NullValueException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.Message); } JobQuery jobQuery = null; if (setJobRetriesDto.JobQuery != null) { jobQuery = setJobRetriesDto.JobQuery.toQuery(ProcessEngine); } try { Batch batch = ProcessEngine.ManagementService.setJobRetriesAsync(setJobRetriesDto.JobIds, jobQuery, setJobRetriesDto.Retries.Value); return(BatchDto.fromBatch(batch)); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.Message); } }
// Get a Batch public static BatchDto GetBatch(int id) { Facade facade = new Facade(); BatchDto batch = facade.GetBatch(id); return(batch); }
private void gvBatches_CommandCellClick(object sender, EventArgs e) { var commandCell = (GridCommandCellElement)sender; var selectedRow = this.gvBatches.SelectedRows.FirstOrDefault(); if (selectedRow == null) { return; } var batch = selectedRow.DataBoundItem as BatchDto; if (batch == null) { return; } if (commandCell.ColumnInfo.Name == GlobalConstants.SelectColumnName) { if (_selectedBatch != batch) { _selectedBatch = batch; LoadMeasures(); } createMeasureWizard.SelectNextPage(); } }
// Get the UserId of the current User public static int?GetUserId() { int batchId; try { batchId = Int32.Parse(HttpContext.Current.Request.QueryString["id"]); } catch { return(null); } Facade facade = new Facade(); BatchDto batch = facade.GetBatch(batchId); int userId; try { userId = batch.UserId; } catch { return(null); } return(userId); }
public virtual BatchDto setRetriesByProcessHistoricQueryBased(SetJobRetriesByProcessDto setJobRetriesDto) { IList <string> processInstanceIds = new List <string>(); HistoricProcessInstanceQueryDto queryDto = setJobRetriesDto.HistoricProcessInstanceQuery; if (queryDto != null) { HistoricProcessInstanceQuery query = queryDto.toQuery(ProcessEngine); IList <HistoricProcessInstance> historicProcessInstances = query.list(); foreach (HistoricProcessInstance historicProcessInstance in historicProcessInstances) { processInstanceIds.Add(historicProcessInstance.Id); } } if (setJobRetriesDto.ProcessInstances != null) { ((IList <string>)processInstanceIds).AddRange(setJobRetriesDto.ProcessInstances); } try { ManagementService managementService = ProcessEngine.ManagementService; Batch batch = managementService.setJobRetriesAsync(processInstanceIds, (ProcessInstanceQuery)null, setJobRetriesDto.Retries.Value); return(BatchDto.fromBatch(batch)); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.Message); } }
public async Task Add(BatchDto dto) { //Get latest batch number int batchNumber = await BatchDataProvider.GetLatestBatchNumber(dto.Beer); Batch entity = new Batch() { Beer = dto.Beer, BatchName = dto.BatchName, BatchNumber = batchNumber + 1, Status = "Planned", Brewers = dto.Brewers, Yeast = dto.Yeast, PreBoilGravity = dto.PreBoilGravity, OriginalGravity = dto.OriginalGravity, FinalGravity = dto.FinalGravity, ABV = dto.ABV, PintsRemaining = dto.PintsRemaining, DateBrewed = dto.DateBrewed, DatePackaged = dto.DatePackaged, DateTapped = dto.DateTapped, BrewingNotes = dto.BrewingNotes, TastingNotes = dto.TastingNotes, Created = DateTime.Now }; await BatchDataProvider.Add(entity); }
// Update a Batch public static bool UpdateBatch(BatchDto batch) { Facade facade = new Facade(); bool result = facade.UpdateBatch(batch); return(result); }
public virtual BatchDto deleteAsyncHistoricQueryBased(DeleteProcessInstancesDto deleteProcessInstancesDto) { IList <string> processInstanceIds = new List <string>(); HistoricProcessInstanceQueryDto queryDto = deleteProcessInstancesDto.HistoricProcessInstanceQuery; if (queryDto != null) { HistoricProcessInstanceQuery query = queryDto.toQuery(ProcessEngine); IList <HistoricProcessInstance> historicProcessInstances = query.list(); foreach (HistoricProcessInstance historicProcessInstance in historicProcessInstances) { processInstanceIds.Add(historicProcessInstance.Id); } } if (deleteProcessInstancesDto.ProcessInstanceIds != null) { ((IList <string>)processInstanceIds).AddRange(deleteProcessInstancesDto.ProcessInstanceIds); } try { RuntimeService runtimeService = ProcessEngine.RuntimeService; Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceIds, null, deleteProcessInstancesDto.DeleteReason, deleteProcessInstancesDto.SkipCustomListeners, deleteProcessInstancesDto.SkipSubprocesses); return(BatchDto.fromBatch(batch)); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.Message); } }
// Create a Battery public static bool CreateBattery(BatteryDto battery) { Facade facade = new Facade(); if (facade.CreateBattery(battery)) { // Remove JobIds from batch if changes made to batteries in batch int batchId = battery.BatchId; BatchDto batch = facade.GetBatch(batchId); batch.DecisionForestRegressionJobId = null; batch.LinearRegressionJobId = null; if (!facade.UpdateBatch(batch)) { return(false); } return(true); } else { return(false); } }
// Create Batch in the database protected void CreateBtn_Click(object sender, EventArgs e) { BatchDto batch = null; try { // Create Batch Object batch = new BatchDto { Batch_Ref = BatchReferenceTb.Text, DecisionForestRegressionJobId = null, LinearRegressionJobId = null, UserId = Int32.Parse(Security.GetQueryString()) }; } catch { Response.Redirect("CreateBatch?message=Error"); } // Add to database if (BatchService.CreateBatch(batch)) { Response.Redirect("Default?message=BatchCreateSuccess"); } else { Response.Redirect("CreateBatch?message=Error"); } }
// Get a Batch in the database public async Task <BatchDto> GetBatch(int id) { BatteryRepository batteryRepository = new BatteryRepository(_context); try { Batch batch = await _context.Batches .Where(b => b.BatchId == id && b.Active == true) .FirstOrDefaultAsync(); BatchDto batchDto = new BatchDto { BatchId = batch.BatchId, Batch_Ref = batch.Batch_Ref, LinearRegressionJobId = batch.LinearRegressionJobId, DecisionForestRegressionJobId = batch.DecisionForestRegressionJobId, UserId = batch.UserId, BatteryCount = batteryRepository.GetBatteries(batch.BatchId).Result.Count, PredictionStatus = PredictionStatus.NotStarted // Set to NotStarted rather than call method to avoid infinite loop }; return(batchDto); } catch { return(null); } }
// Populate the page with entity data private void PopulatePage() { int batchId = 0; try { // Get object from BatchApi batchId = Int32.Parse(Security.GetQueryString()); BatchDto batch = BatchService.GetBatch(batchId); BatchReferenceTb.Text = batch.Batch_Ref; } catch { // ERROR - User contained invalid data Response.Redirect("BatchDetail?Id{" + batchId + "}&message=DatabaseError"); } List <BatteryDto> batteries = BatteryService.GetBatteries(batchId); if (batteries.Count > 0) { // If there are batteries in this batch; display the gridview BatteryGridView.DataSource = batteries; BatteryGridView.DataBind(); } else { // Otherwise hide the gridview and display an alternative message hiddenDiv.Visible = true; SubtitleDiv.Visible = false; DownloadDiv.Visible = false; } }
internal static BatchDto MapToBatch(BatchRow pBatchRow, InventoryLotRow pInventoryLotRow, GenerationRequestRow pGenerationRequestRow) { if (pBatchRow == null || pInventoryLotRow == null || pGenerationRequestRow == null) { return(null); } var _batch = new BatchDto(); _batch.BatchId = pBatchRow.Batch_id; _batch.InventoryStatus = pBatchRow.InventoryStatus; _batch.BoxId = pBatchRow.Box_id; _batch.CustomerAcctId = pBatchRow.Customer_acct_id; _batch.FirstSerial = pBatchRow.First_serial; _batch.LastSerial = pBatchRow.Last_serial; _batch.RequestId = pBatchRow.Request_id; _batch.Selected = false; _batch.LotId = pInventoryLotRow.Lot_id; _batch.ServiceId = pInventoryLotRow.Service_id; _batch.Denomination = pInventoryLotRow.Denomination; _batch.NumberOfBatches = pGenerationRequestRow.Number_of_batches; _batch.BatchSize = pGenerationRequestRow.Batch_size; _batch.DateRequested = pGenerationRequestRow.Date_requested; _batch.DateToProcess = pGenerationRequestRow.Date_to_process; _batch.DateCopleted = pGenerationRequestRow.Date_completed; return(_batch); }
public IResult Batch([FromRoute] string cmd, [FromBody] BatchDto dto) { BatchOperation opCode; if (!Enum.TryParse(cmd, ignoreCase: true, out opCode)) { return(ErrorCode.UnSupported.ToResult()); } return(base.Batch(opCode, dto)); }
public async Task <ActionResult <BatchDto> > Detail(int id) { BatchDto batch = await _batchRepository.GetBatch(id); if (batch == null) { return(NotFound()); } return(Ok(batch)); }
/// <summary> /// Attempts to add a new batch after ensuring that the data entered is valid /// </summary> public async Task <bool> AddNewBatch(BatchDto newBatch) { if (batchLogic.ValidateRestData(newBatch)) { return(await client.InsertBatchAsync(batchLogic.MapToSoap(newBatch))); } else { return(false); } }
public HttpResponseMessage AddBatch(BatchDto batch) { var repository = new BatchRepository(); var result = repository.Create(batch.RecipeId, batch.Cooker); if (result) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Batch could not be created, try again.")); }
/// <summary> /// Changes the active status of a batch /// This is essentially the 'Delete' method /// </summary> public async Task <bool> DeactivateBatch(BatchDto delBatch) { if (batchLogic.ValidateRestData(delBatch)) { return(await client.DeleteBatchAsync(batchLogic.MapToSoap(delBatch))); } else { return(false); } }
public async Task <ActionResult <Batch> > Create([FromBody] BatchDto batch) { Batch entity = await _batchRepository.CreateBatch(batch); if (entity == null) { return(NotFound()); } return(Ok(entity)); }
// Redirect to home page if the Batch associated with with BatchId is not Active public static void RedirectIfBatchIsNotActive() { int batchId = Int32.Parse(Security.GetQueryString()); Facade facade = new Facade(); BatchDto batch = facade.GetBatch(batchId); if (batch == null) { RedirectToHomePage(); } }
public async Task <IActionResult> Put([FromBody] BatchDto dto) { try { await BatchService.Update(dto); return(NoContent()); } catch (Exception ex) { Log.Error($"Error updating batch with ID \"{dto.Id}\"."); throw; } }
/// <summary> /// This is the basic 'Update' method for Batch /// </summary> public async Task <bool> UpdateBatch(BatchDto update) { if (batchLogic.ValidateRestData(update)) { var keepStatus = batchLogic.MapToSoap(update); keepStatus.Active = true; return(await client.UpdateBatchAsync(keepStatus)); } else { return(false); } }
public virtual BatchDto executeModificationAsync(ModificationDto modificationExecutionDto) { Batch batch = null; try { batch = createModificationBuilder(modificationExecutionDto).executeAsync(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.Message); } return(BatchDto.fromBatch(batch)); }
public virtual BatchDto updateSuspensionStateAsync(ProcessInstanceSuspensionStateDto dto) { Batch batch = null; try { batch = dto.updateSuspensionStateAsync(ProcessEngine); return(BatchDto.fromBatch(batch)); } catch (BadUserRequestException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e.Message); } }
public async Task InsertBatchAsync(byte batchStatus, Guid guid, int totalBatchItems) { var dto = new BatchDto() { StatusId = batchStatus, Guid = guid, CreatedAt = DateTime.UtcNow, TotalBatchItems = totalBatchItems }; await _db.Batch.AddAsync(dto); await _db.SaveChangesAsync(); }
public virtual BatchDto restartProcessInstanceAsync(RestartProcessInstanceDto restartProcessInstanceDto) { Batch batch = null; try { batch = createRestartProcessInstanceBuilder(restartProcessInstanceDto).executeAsync(); } catch (BadUserRequestException e) { throw new InvalidRequestException(Response.Status.BAD_REQUEST, e.Message); } return(BatchDto.fromBatch(batch)); }
private void gvBatches_CommandCellClick(object sender, EventArgs e) { var commandCell = (GridCommandCellElement)sender; var selectedRow = this.gvBatches.SelectedRows.FirstOrDefault(); if (selectedRow == null) return; var batch = selectedRow.DataBoundItem as BatchDto; if (batch == null) return; if (commandCell.ColumnInfo.Name == GlobalConstants.SelectColumnName) { _selectedBatch = batch; createMeasureWizard.SelectNextPage(); } }
private void createMeasureWizard_SelectedPageChanging(object sender, SelectedPageChangingEventArgs e) { if (e.NextPage == wizardPage2) { if (gvBatches.SelectedRows.Count == 1) { var selectedBatch = gvBatches.SelectedRows.Single().DataBoundItem as BatchDto; _selectedBatch = selectedBatch; } else { RadMessageBox.Show("Debe seleccionar un lote para continuar"); e.Cancel = true; } } if (e.NextPage == wizardCompletionPage1) { ValidateMeasures(e); } }