Beispiel #1
0
        public async Task Handle(UpdateDailyExtractLotCommand message)
        {
            var result = false;

            var dailyExtractLot = await _dailyExtractLotRepository.GetById(message.DailyExtractLotId);

            if (dailyExtractLot != null)
            {
                if (dailyExtractLot.Name != message.Name)
                {
                    dailyExtractLot.ChangeName(message.Name);
                }

                if (dailyExtractLot.ManagementCategoryId != message.ManamementCategoryId)
                {
                    var managementCategory = await _dailyExtractLotRepository.GetManagementCategoryById(message.ManamementCategoryId);

                    dailyExtractLot.ChangeManagementCategory(managementCategory);
                }

                if (!dailyExtractLot.IsValid())
                {
                    var messageType = message.GetType().Name;
                    foreach (var error in dailyExtractLot.ValidationResult.Errors)
                    {
                        await NotifyError(messageType, error.ErrorMessage);
                    }
                }
                else
                {
                    _dailyExtractLotRepository.Update(dailyExtractLot);

                    result = await _uow.SaveChangesAsync();

                    if (result)
                    {
                        await _bus.RaiseIntegrationEvent(new UpdatedDailyExtractLotEvent(message.AggregateId, dailyExtractLot.Id, dailyExtractLot.ManagementCategoryId, dailyExtractLot.HeadsAmount));
                    }
                }
            }
        }
Beispiel #2
0
        public async Task <(DailyExtractLot, bool)> CreateNewDailyExtractLot(string name, Guid managementCategoryId, int headsAmount)
        {
            var isNewDailyExtractLot = false;

            DailyExtractLot dailyExtractLot = null;

            dailyExtractLot = await _dailyExtractLotRepository.GetDailyExtractLotByManagementCategoryId(managementCategoryId);

            if (dailyExtractLot != null)
            {
                dailyExtractLot.IncreateHeadsAmount(headsAmount);
                _dailyExtractLotRepository.Update(dailyExtractLot);
            }
            else
            {
                dailyExtractLot = new DailyExtractLot(name, managementCategoryId, headsAmount);
                _dailyExtractLotRepository.Add(dailyExtractLot);
                isNewDailyExtractLot = true;
            }

            return(dailyExtractLot, isNewDailyExtractLot);
        }