Ejemplo n.º 1
0
        public async Task <ActionResult> Create(PartnerViewModel partnerVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(partnerVm));
            }

            _partnerRepository.Add(partnerVm.Map <Partner>());

            await UnitOfWork.CompleteAsync();

            return(View("List"));
        }
        public async Task <IHttpActionResult> UpdateAsync(int id, PartnerDto partner)
        {
            var partnerInDb = await _partnerRepository.GetAsync(id);

            if (partnerInDb == null)
            {
                return(NotFound());
            }

            _partnerRepository.Add(partner.Map <Partner>());

            await UnitOfWork.CompleteAsync();

            return(Ok());
        }
        public Task <bool> Handle(CreatePartnerCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var partner = new Partner(message.Id, message.TradingName, message.OwnerName, message.Document, message.CoverageArea, message.Address, message.DeserializedCoverageArea, message.DeserializedAddress);

            if (_partnerRepository.GetById(partner.Id) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "The partner id has already been taken."));
                return(Task.FromResult(false));
            }
            else if (_partnerRepository.GetAll().Where(x => x.Document == partner.Document).Count() > 0)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "The document has already been taken."));
                return(Task.FromResult(false));
            }

            _partnerRepository.Add(partner);

            if (Commit())
            {
                Bus.RaiseEvent(new PartnerCreatedEvent(partner.Id, partner.TradingName, partner.OwnerName, partner.Document, partner.CoverageArea, partner.Address, message.DeserializedCoverageArea, message.DeserializedAddress));
            }

            return(Task.FromResult(true));
        }
        public void Add(string name, string businessName, string businessNumber)
        {
            if (!string.IsNullOrWhiteSpace(businessNumber))
            {
                if (!_partnerRepository.BusinessNumberExists(businessNumber))
                {
                    Partner partnerDomainModel = Partner.CreateNewPartner(name, businessName, businessNumber);
                    _partnerRepository.Add(partnerDomainModel);
                    return;
                }

                throw new Exception("BusinessNumber already exists");
            }

            throw new Exception("BusinessNumber cannot be null or empty");
        }
Ejemplo n.º 5
0
        public void CreatePartner(PartnerViewModel partner)
        {
            var partnerInsert = Mapper.Map <PartnerViewModel, Partner_M>(partner);

            _partnerRepository.Add(partnerInsert);

            //if (partner.Settlement != null)
            //{
            //	var settlement = Mapper.Map<PartnerSettlementViewModel, PartnerSettlement_M>(partner.Settlement);
            //	_partnerSettlementRepository.Add(settlement);
            //}
            if (partner.SettlementList != null && partner.SettlementList.Count > 0)
            {
                _partnerSettlementRepository.Delete(set => set.PartnerMainC == partner.InvoiceMainC && set.PartnerSubC == partner.InvoiceSubC);
                SavePartner();
                for (var iloop = 0; iloop < partner.SettlementList.Count; iloop++)
                {
                    var settlement = Mapper.Map <PartnerSettlementViewModel, PartnerSettlement_M>(partner.SettlementList[iloop]);
                    _partnerSettlementRepository.Add(settlement);
                }
            }

            //insert init partner payment
            var initPartnerPayment = new PartnerBalance_D()
            {
                PartnerMainC     = partner.PartnerMainC,
                PartnerSubC      = partner.PartnerSubC,
                PartnerBalanceD  = new DateTime(1900, 1, 1),
                PartnerFee       = 0,
                PartnerExpense   = 0,
                PartnerSurcharge = 0,
                PartnerDiscount  = 0,
                TotalAmount      = partner.InitPartnerPayment ?? 0,
                TaxAmount        = 0,
                PaymentAmount    = 0
            };

            _partnerBalanceRepository.Add(initPartnerPayment);

            SavePartner();
        }
Ejemplo n.º 6
0
 public IActionResult AddPartner([FromBody] Partner model)
 {
     model.Display = model.FirstName + " " + model.LastName;
     partner_repo.Add(model);
     return(new OkObjectResult(new { PartnerId = model.PartnerId }));
 }