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(); }
public void UpdatePartner(PartnerViewModel partner) { var updatePartner = Mapper.Map <PartnerViewModel, Partner_M>(partner); _partnerRepository.Update(updatePartner); //if (partner.Settlement != null) //{ // var settlement = Mapper.Map<PartnerSettlementViewModel, PartnerSettlement_M>(partner.Settlement); // var set = _partnerSettlementRepository.Query( i => // i.ApplyD == settlement.ApplyD && i.PartnerMainC == updatePartner.PartnerMainC && // i.PartnerSubC == updatePartner.PartnerSubC).FirstOrDefault(); // if (set != null) // { // _partnerSettlementRepository.Delete(set); // _partnerSettlementRepository.Add(settlement); // } // else // { // _partnerSettlementRepository.Add(settlement); // } //} if (partner.SettlementList != null && partner.SettlementList.Count > 0) { _partnerSettlementRepository.Delete(set => set.PartnerMainC == updatePartner.InvoiceMainC && set.PartnerSubC == updatePartner.InvoiceSubC); SavePartner(); for (var iloop = 0; iloop < partner.SettlementList.Count; iloop++) { var settlement = Mapper.Map <PartnerSettlementViewModel, PartnerSettlement_M>(partner.SettlementList[iloop]); _partnerSettlementRepository.Add(settlement); } } //Update init partner payment var currInitPartnerPayment = _partnerBalanceRepository.Get(p => p.PartnerMainC == partner.PartnerMainC & p.PartnerSubC == partner.PartnerSubC & p.PartnerBalanceD == new DateTime(1900, 1, 1)); if (currInitPartnerPayment != null) { currInitPartnerPayment.TotalAmount = partner.InitPartnerPayment ?? 0; _partnerBalanceRepository.Update(currInitPartnerPayment); } else { 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(); }