private void BtnGuardar_Click(object sender, EventArgs e) { if (!ValidateForm()) { this.DialogResult = DialogResult.None; return; } using (var service = _serviceFactory.Create<IBatchService>()) { var moveNextStageDto = new MoveNextStageDto(); moveNextStageDto.BatchId = _stateController.CurrentSelectedBatch.Id; moveNextStageDto.NextStageStartDate = dtpDate.Value; moveNextStageDto.CurrentFoodStock = txtCurrentStockFood.Value; foreach (var barnAssigned in ucAssignBarns.BarnsAssigned) { moveNextStageDto.BarnsAssigned.Add(new BarnsAssignedDto() { BarnId = barnAssigned.BarnId, InitialBirds = barnAssigned.BirdsAmount }); } service.MoveNextStage(moveNextStageDto); OnBatchStageChanged(); } }
public void MoveNextStage(MoveNextStageDto nextStageDto) { var batch = GetById(nextStageDto.BatchId); if (batch.StageId == Stage.POSTURE) { throw new ApplicationException("El lote ya se encuentra en la ultima etapa de postura"); } var currentStage = batch.StageId; var nextStage = Stage.NextStageId(batch.StageId); var stageChange = new StageChange(); stageChange.BatchId = batch.Id; stageChange.StageFromId = currentStage; stageChange.StageToId = nextStage; stageChange.CurrentFoodStock = nextStageDto.CurrentFoodStock; stageChange.FoodEntryDuringPeriod = GetCurrentStageFoodEntry(batch.Id, nextStageDto.NextStageStartDate, nextStage); stageChange.StageFromInitialBirds = GetInitialBirds(batch.Id, currentStage); stageChange.StageFromIFinalBirds = GetBirdsAmount(batch.Id, nextStageDto.NextStageStartDate); Uow.StageChanges.Add(stageChange); batch.StageId = nextStage; if (nextStage == Stage.REBREEDING) { batch.ReBreedingDate = nextStageDto.NextStageStartDate; } else if (nextStage == Stage.POSTURE) { batch.PostureDate = nextStageDto.NextStageStartDate; } Uow.Batches.Edit(batch); foreach (var barn in nextStageDto.BarnsAssigned) { Uow.BatchBarns.Add(new BatchBarn() { BatchId = batch.Id, BarnId = barn.BarnId, InitialBirds = (int)barn.InitialBirds }); } Uow.Commit(); }