public HostPayment Save(HostPayment hostPayment) { NullArgumentChecker.CheckIfNull(hostPayment, "hostPayment"); var hostPaymentEntity = _hostPaymentFactory.CreateHostPaymentEntity(hostPayment); using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter()) { if (!myAdapter.SaveEntity(hostPaymentEntity, true)) { throw new PersistenceFailureException(); } var address = _addressRepository.GetAddress(hostPaymentEntity.MailingAddressId.Value); return(_hostPaymentFactory.CreateHostPayment(hostPaymentEntity, address)); } }
public HostPaymentEntity CreateHostPaymentEntity(HostPayment hostPayment) { return(new HostPaymentEntity(hostPayment.Id) { HostId = hostPayment.HostId, Amount = hostPayment.Amount, PaymentMode = (long)hostPayment.PaymentMode, PayableTo = hostPayment.PayableTo, MailingAttentionOf = hostPayment.MailingAttentionOf, MailingOrganizationName = hostPayment.MailingOrganizationName, DueDate = hostPayment.DueDate, Status = (long)hostPayment.Status, DateCreated = hostPayment.CreatedDate, EventId = hostPayment.EventId, IsDeposit = false, MailingAddressId = hostPayment.PaymentMailingAddress.Id, CreatorOrganizationRoleUserId = hostPayment.PaymentRecordedBy.Id, IsActive = hostPayment.IsActive, IsNew = hostPayment.Id == 0 }); }
public void CreateHostDeposit(HostPaymentEntity hostPaymentEntity, HostPayment hostPayment, Address address) { hostPayment.Id = hostPaymentEntity.HostPaymentId; hostPayment.HostId = hostPaymentEntity.HostId; hostPayment.Amount = hostPaymentEntity.Amount; hostPayment.CreatedDate = hostPaymentEntity.DateCreated; hostPayment.DueDate = hostPaymentEntity.DueDate; hostPayment.EventId = hostPaymentEntity.EventId; hostPayment.MailingAttentionOf = hostPaymentEntity.MailingAttentionOf; hostPayment.MailingOrganizationName = hostPaymentEntity.MailingOrganizationName; hostPayment.PaymentMode = (HostPaymentType)hostPaymentEntity.PaymentMode; hostPayment.Status = (HostPaymentStatus)hostPaymentEntity.Status; hostPayment.PayableTo = hostPaymentEntity.PayableTo; hostPayment.PaymentMailingAddress = address; hostPayment.PaymentRecordedBy = hostPaymentEntity.CreatorOrganizationRoleUserId != null ? new OrganizationRoleUser(hostPaymentEntity.CreatorOrganizationRoleUserId.Value) : null; hostPayment.IsActive = hostPaymentEntity.IsActive; hostPayment.HostPaymentTransactions = _mapper.MapMultiple(hostPaymentEntity.HostPaymentTransaction).ToList(); }
public bool UpdateHostPaymentStatusAndNotes(long hostPaymentId, decimal amount, int hostPaymentStatus, int hostPaymentType, string notes, string paymentDate, long organizationRoleUserId, long hostId, string taxIdNumber, bool isDeposit) { DateTime transactionDate = DateTime.Now; int hostPaymentStatusOld = hostPaymentStatus; if (!string.IsNullOrEmpty(paymentDate)) { transactionDate = Convert.ToDateTime(paymentDate); } try { HostDeposit hostDepositInfo = null; HostPayment hostPaymentInfo = null; HostPaymentStatus currentPaymentStatus; if (isDeposit) { hostDepositInfo = _hostDepositRepository.GetByHostDepositById(hostPaymentId); if (hostDepositInfo != null && hostDepositInfo.DepositApplicablityMode == DepositType.Refunded && hostPaymentStatus == (int)HostPaymentStatus.Paid) { hostPaymentStatus = (int)HostPaymentStatus.Receivable; } currentPaymentStatus = hostDepositInfo != null ? hostDepositInfo.Status : HostPaymentStatus.Pending; } else { hostPaymentInfo = _hostPaymentRepository.GetHostPaymentById(hostPaymentId); currentPaymentStatus = hostPaymentInfo != null ? hostPaymentInfo.Status : HostPaymentStatus.Pending; } //using (var transaction = new TransactionScope()) //{ // Update Host Payment _hostPaymentRepository.UpdateHostPaymentStatusAndNotes(hostPaymentId, amount, hostPaymentStatus); if (hostPaymentStatusOld == (int)HostPaymentStatus.Paid || hostPaymentStatusOld == (int)HostPaymentStatus.Refunded) { var hostPaymentTransaction = new HostPaymentTransaction() { HostPaymentId = hostPaymentId, TransactionType = (HostPaymentStatus)hostPaymentStatusOld, TransactionMethod = (HostPaymentType)hostPaymentType, Amount = amount, Notes = notes, TransactionDate = transactionDate, TransactionRecordedBy = organizationRoleUserId > 0 ? new OrganizationRoleUser( organizationRoleUserId) : null }; var hostPaymentTransactionExisting = _hostPaymentTransactionRepository.GetByIdAndStatus(hostPaymentId, hostPaymentStatusOld); if (hostPaymentTransactionExisting == null) { if ((hostPaymentStatusOld == (int)HostPaymentStatus.Paid && currentPaymentStatus != HostPaymentStatus.Paid) || (hostPaymentStatusOld == (int)HostPaymentStatus.Refunded && currentPaymentStatus != HostPaymentStatus.Refunded) ) { _hostPaymentTransactionRepository.Save(hostPaymentTransaction); } } else { if ((hostPaymentStatusOld == (int)HostPaymentStatus.Paid && currentPaymentStatus != HostPaymentStatus.Paid) || (hostPaymentStatusOld == (int)HostPaymentStatus.Refunded && currentPaymentStatus != HostPaymentStatus.Refunded) ) { _hostPaymentTransactionRepository.UpdateHostPaymentTransactionByIdAndStatus( hostPaymentTransaction); } } } // delete (Paid to Pending(Delete Paid)) if ((currentPaymentStatus == HostPaymentStatus.Paid) && (hostPaymentStatusOld == (int)HostPaymentStatus.Pending)) { _hostPaymentTransactionRepository.DeleteByIdAndStatus(hostPaymentId, currentPaymentStatus); } // delete (Refunded to Paid (Delete Refunded)) else if ((currentPaymentStatus == HostPaymentStatus.Refunded) && (hostPaymentStatusOld == (int)HostPaymentStatus.Paid)) { _hostPaymentTransactionRepository.DeleteByIdAndStatus(hostPaymentId, currentPaymentStatus); } // delete (Refunded to Pending (Both records)) //else if ((currentPaymentStatus == HostPaymentStatus.Refunded) && (hostPaymentStatus == (int)HostPaymentStatus.Pending)) // { // _hostPaymentTransactionRepository.DeleteByIdAndStatus(hostPaymentId, currentPaymentStatus); // _hostPaymentTransactionRepository.DeleteByIdAndStatus(hostPaymentId, HostPaymentStatus.Paid); // } if (!string.IsNullOrEmpty(taxIdNumber)) { _hostRepository.UpdateHostTaxIdNumber(hostId, taxIdNumber); } //transaction.Complete(); //} return(true); } catch (Exception) { return(false); } }
public static List <EventHostDepositViewData> HostPaymentViewData(this IEnumerable <HostPayment> hostPayments, IEnumerable <Event> events, IEnumerable <Host> hosts) { var eventHostDepositViewDatas = new List <EventHostDepositViewData>(); foreach (var hostPayment in hostPayments) { if (hostPayment != null) { HostPayment payment = hostPayment; var currentEvent = events.SingleOrDefault(e => e.Id == payment.EventId); var host = hosts.SingleOrDefault(h => h.Id == payment.HostId); if (host != null && currentEvent != null) { var eventHostDepositViewData = new EventHostDepositViewData { IsDeposit = false, EventId = hostPayment.EventId, EventDate = currentEvent.EventDate, EventStatus = currentEvent.Status, TaxIdNumber = !string.IsNullOrEmpty(host.TaxIdNumber) ? host.TaxIdNumber : string.Empty, Name = currentEvent.Name, EventStreetAddressLine1 = host.Address.StreetAddressLine1, EventStreetAddressLine2 = host.Address.StreetAddressLine2, EventCity = host.Address.City, EventState = host.Address.State, EventZip = host.Address.ZipCode != null ? host.Address.ZipCode.Zip:string.Empty, EventCountry = host.Address.Country, HostId = hostPayment.HostId, Amount = hostPayment.Amount, PaymentMode = hostPayment.PaymentMode, DueDate = hostPayment.DueDate, PayableTo = hostPayment.PayableTo, MailingAttentionOf = hostPayment.MailingAttentionOf, MailingOrganizationName = hostPayment.MailingOrganizationName, AddressId = hostPayment.PaymentMailingAddress.Id, StreetAddressLine1 = hostPayment.PaymentMailingAddress.StreetAddressLine1, StreetAddressLine2 = hostPayment.PaymentMailingAddress.StreetAddressLine2, City = hostPayment.PaymentMailingAddress.City, State = hostPayment.PaymentMailingAddress.State, Zip = hostPayment.PaymentMailingAddress.ZipCode != null ? hostPayment.PaymentMailingAddress.ZipCode.Zip : string.Empty, Country = hostPayment.PaymentMailingAddress.Country, Status = hostPayment.Status, IsActive = hostPayment.IsActive, Id = hostPayment.Id, HostPaymentTransactions = hostPayment.HostPaymentTransactions }; eventHostDepositViewDatas.Add(eventHostDepositViewData); } } } return(eventHostDepositViewDatas); }