public async Task <bool> AddAsync(DetailDTO detailDTO)
        {
            var detail = _mapper.Map <DetailDTO, Detail>(detailDTO);
            var result = await _detailRepository.Add(detail);

            return(result);
        }
        public ActionResult <Detail> PostDetail(DetailDTO detailDTO)
        {
            Detail detailToCreate = new Detail(detailDTO.LangeBeschrijving, detailDTO.BewoonbareOppervlakte, detailDTO.TotaleOppervlakte, detailDTO.EPCWaarde, detailDTO.KadastraalInkomen);

            _detailRepository.Add(detailToCreate);
            _detailRepository.SaveChanges();

            return(CreatedAtAction(nameof(GetDetail), new { id = detailToCreate.DetailID }, detailToCreate));
        }
Beispiel #3
0
        public Task <bool> Handle(CreateNewDetailCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                Task.FromResult(false);
            }
            var detail = new Detail(request.DetailId, request.DetailName, request.DetailFeature, request.Category);

            if (_detailRepository.GetById(detail.DetailId) != null)
            {
                _bus.RaiseEvent(new DomainNotification(request.MessageType, "The detail has already been created."));
                return(Task.FromResult(false));
            }
            _detailRepository.Add(detail);

            if (Commit())
            {
                _bus.RaiseEvent(new DetailCreatedEvent(detail.DetailId, detail.DetailName, detail.DetailFeature, detail.Category));
            }
            return(Task.FromResult(true));
        }
Beispiel #4
0
        public async Task Run(
            [ServiceBusTrigger("ams", "raw", Connection = "QueueConnection")] string mySbMsg
            , CancellationToken cancellationToken)
        {
            try
            {
                var raw = JsonSerializer.Deserialize <RawData>(mySbMsg);
                _rawRepository.Add(raw);
                var result = await _rawRepository.SaveChangesAsync(cancellationToken);

                var hdlcMessage = ParseMessage(raw.Raw);
                foreach (var data in hdlcMessage.Data)
                {
                    var detail = new Detail()
                    {
                        MeasurementId = raw.MeasurementId,
                        TimeStamp     = raw.TimeStamp,
                        Location      = raw.Location,
                        ObisCode      = data.ObisCode,
                        Unit          = data.Unit,
                        Name          = data.Name,
                        ValueStr      = data.Name,
                        ValueNum      = data.Value
                    };

                    _detailRepository.Add(detail);

                    Console.WriteLine(JsonSerializer.Serialize(detail));
                }

                result += await _detailRepository.SaveChangesAsync(cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #5
0
        public async Task <SaleDto> Create(Guid userId, SaleForCreationDto saletForCreationDto)
        {
            try
            {
                Client client = null;
                if (saletForCreationDto.ClientId.HasValue)
                {
                    client = await _clientRepository.GetById(saletForCreationDto.ClientId.Value);

                    if (client == null)
                    {
                        throw new KeyNotFoundException($"Client with id: {saletForCreationDto.ClientId} not found.");
                    }
                }

                var sale = new Sale()
                {
                    ClientId    = saletForCreationDto.ClientId,
                    ClientName  = client != null ? client.Name + " " + client.Lastname : saletForCreationDto.ClientName,
                    Date        = saletForCreationDto.Date.ToLocalTime(),
                    PaymentType = saletForCreationDto.PaymentType,
                    CreatedBy   = userId
                };

                decimal total = 0;
                foreach (var detailFC in saletForCreationDto.Details)
                {
                    var product = await _productRepository.GetById(detailFC.ProductId);

                    if (product == null)
                    {
                        throw new KeyNotFoundException($"Product with id: {detailFC.ProductId} not found.");
                    }

                    var price = (await _priceRepository.GetAll())
                                .OrderByDescending(x => x.DateTime)
                                .FirstOrDefault(
                        x => x.ProductId == detailFC.ProductId &&
                        x.DateTime.ToLocalTime() <= saletForCreationDto.Date.ToLocalTime() &&
                        x.PriceType == ePriceTypes.SalePrice &&
                        !x.IsDeleted
                        );

                    FeeRule feeRule = null;
                    if (sale.PaymentType == ePaymentTypes.OwnFees)
                    {
                        feeRule = (await _feeRuleRepository.Find(x => x.ProductId == detailFC.ProductId))
                                  .OrderByDescending(x => x.Date).ThenBy(x => x.FeesAmountTo)
                                  .FirstOrDefault(x => x.Date <= sale.Date && x.FeesAmountTo >= saletForCreationDto.OwnFees.Quantity);
                        if (feeRule == null)
                        {
                            throw new KeyNotFoundException($"Fee Rule not found.");
                        }

                        decimal percentage = feeRule.Percentage * saletForCreationDto.OwnFees.Quantity / 100;
                        total += price.Value * detailFC.Quantity * (1 + percentage);
                    }
                    else
                    {
                        total += price.Value * detailFC.Quantity;
                    }

                    var detail = new Detail()
                    {
                        SaleId    = sale.Id,
                        ProductId = detailFC.ProductId,
                        Quantity  = detailFC.Quantity,
                        UnitPrice = price.Value,
                        FeeRuleId = feeRule?.Id,
                        CreatedBy = userId
                    };
                    product.Stock -= detailFC.Quantity;

                    detail = await _detailRepository.Add(detail);

                    await _productRepository.Update(product);
                }

                Payment payment = null;
                switch (saletForCreationDto.PaymentType)
                {
                case Util.Enums.ePaymentTypes.Cash:
                    var cashDto = (CashForCreationDto)saletForCreationDto.Cash;
                    payment = new Cash(total, cashDto.Discount)
                    {
                        SaleId    = sale.Id,
                        CreatedBy = userId
                    };

                    await _cashRepository.Add((Cash)payment);

                    break;

                case Util.Enums.ePaymentTypes.OwnFees:
                    var ownFeesDto = (OwnFeesForCreationDto)saletForCreationDto.OwnFees;
                    payment = new OwnFees(ownFeesDto.ExpirationDate, total, ownFeesDto.Quantity, userId)
                    {
                        SaleId = sale.Id,
                    };

                    payment = await _ownFeesRepository.Add((OwnFees)payment);

                    foreach (var fee in ((OwnFees)payment).FeeList)
                    {
                        await _feeRepository.Add(fee);
                    }
                    break;

                case Util.Enums.ePaymentTypes.CreditCard:
                    var creditCardDto = (CreditCardForCreationDto)saletForCreationDto.CreditCard;
                    payment = new CreditCard(total, creditCardDto.Discount, creditCardDto.Surcharge)
                    {
                        SaleId    = sale.Id,
                        CardType  = creditCardDto.CardType,
                        Bank      = creditCardDto.Bank,
                        CreatedBy = userId
                    };

                    await _creditCardRepository.Add((CreditCard)payment);

                    break;

                case Util.Enums.ePaymentTypes.DebitCard:
                    var debitCardDto = (DebitCardForCreationDto)saletForCreationDto.DebitCard;
                    payment = new DebitCard(total, debitCardDto.Discount, debitCardDto.Surcharge)
                    {
                        SaleId    = sale.Id,
                        CardType  = debitCardDto.CardType,
                        Bank      = debitCardDto.Bank,
                        CreatedBy = userId
                    };

                    await _debitCardRepository.Add((DebitCard)payment);

                    break;

                case Util.Enums.ePaymentTypes.Cheques:
                    var chequesDto = (ChequesPaymentForCreationDto)saletForCreationDto.Cheques;

                    if (chequesDto.ListOfCheques.Sum(x => x.Value) != total)
                    {
                        throw new InvalidOperationException("The sum of cheques list is different of amount.");
                    }

                    payment = new ChequesPayment()
                    {
                        SaleId    = sale.Id,
                        Amount    = Math.Ceiling(total * 100) / 100,
                        CreatedBy = userId
                    };

                    await _chequesPaymentRepository.Add((ChequesPayment)payment);

                    foreach (var c in chequesDto.ListOfCheques)
                    {
                        var cheque = new Cheque()
                        {
                            ChequesPaymentId = payment.Id,
                            Bank             = c.Bank,
                            Nro       = c.Nro,
                            Value     = c.Value,
                            CreatedBy = userId
                        };

                        await _chequeRepository.Add(cheque);
                    }
                    break;

                default:
                    break;
                }

                sale.PaymentId = payment.Id;
                sale           = await _saleRepository.Add(sale);

                await _saleRepository.CommitAsync();

                return(_mapper.Map <Sale, SaleDto>(sale));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void Add(Detail assetDetail)
 {
     repository.Add(assetDetail);
 }