Пример #1
0
        private void OpenProfileDetailWindow(AssociationUser profile, AssociationUserAddress homeAddress, AssociationUserAddress workAddress, AssociationUserCreditCard creditCard, AssociationUserBillingAccount billingAccount, bool isAdd)
        {
            var view = Kernel.Get<ProfileDetailChildWindow>();
            var viewModel = Kernel.Get<ProfileDetailChildWindowViewModel>();
            viewModel.Profile = profile;
            viewModel.Manager = _manager;
            viewModel.ProfileHomeAddress = homeAddress != null ? homeAddress : new AssociationUserAddress { Country = _manager.Country, Nickname = "Home", Type = AddressType.Home };
            viewModel.ProfileWorkAddress = workAddress != null ? workAddress : new AssociationUserAddress { Country = _manager.Country, Nickname = "Work", Type = AddressType.Work };
            viewModel.ProfileDefaultCreditCard = creditCard;
            viewModel.ProfileDefaultBillingAccount = billingAccount;
            viewModel.IsAdd = isAdd;

            view.DataContext = viewModel;

            viewModel.Completed += (o, e) =>
            {
                view.DialogResult = true;
                e.Value.CurrentManagerId = _manager.Id;
                Profiles.Replace(e.Value);
                SelectedProfile = e.Value;
            };

            viewModel.Cancelled += (o, e) =>
                {
                    //if (e.Value.Id == _managerId)
                    //    e.Value.IsManager = true;
                    e.Value.CurrentManagerId = _manager.Id;
                    Profiles.Replace(e.Value);
                    SelectedProfile = e.Value;
                };

            view.Show();
        }
 public SavedBillingAccountViewModel(AssociationUser profile, ObservableCollection<AssociationBillingAccount> billingAccounts, AssociationUserBillingAccount savedBillingAccount)
 {
     SavedBillingAccount = savedBillingAccount;
     BillingAccounts = billingAccounts;
     Profile = profile;
 }
Пример #3
0
        public SubmitBookingResponse Submit(int bookingId)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    db.Connection.Open();
                    using (var transaction = db.Connection.BeginTransaction())
                    {
                        var booking = db.Bookings.IncludeAll("ChargeInfo", "PaymentInfo.CreditCard", "PaymentInfo.CreditCard.Info", "PaymentInfo.CreditCard.Address", "PaymentInfo.BillingAccount", "PaymentInfo.BillingAccount.ChargeBack", "PaymentInfo.Items").FirstOrDefault(b => b.Id == bookingId);

                        booking.Status = BookingStatus.Confirmed;
                        db.Bookings.ApplyChanges(booking);
                        db.SaveChanges();

                        var response = new SubmitBookingResponse();
                        response.CreatorEmails = db.AssociationUserEmails.Where(e => e.AssociationUserId == booking.CreatorId && e.IsActivated).Select(e => e.Email).ToList();

                        if (booking.PaymentInfo != null)
                        {
                            if (booking.PaymentInfo.CreditCard != null)
                            {
                                //add to saved billing
                                if (!string.IsNullOrWhiteSpace(booking.PaymentInfo.CreditCard.SavedCreditCardNickname) && booking.PaymentInfo.CreditCard.SavedCreditCardId == 0)
                                {
                                    var CreditCard = new AssociationUserCreditCard();
                                    CreditCard.AssociationUserId = booking.PaymentInfo.AssociationUserId;
                                    CreditCard.TypeId = booking.PaymentInfo.CreditCard.TypeId;
                                    CreditCard.Holder = booking.PaymentInfo.CreditCard.Holder;
                                    CreditCard.ExpiryMonth = booking.PaymentInfo.CreditCard.ExpiryMonth;
                                    CreditCard.ExpiryYear = booking.PaymentInfo.CreditCard.ExpiryYear;
                                    CreditCard.Nickname = booking.PaymentInfo.CreditCard.SavedCreditCardNickname;
                                    db.AssociationUserCreditCards.ApplyChanges(CreditCard);
                                    db.SaveChanges();

                                    CreditCard.Info = new AssociationUserCreditCardInfo();
                                    CreditCard.Info.CardId = CreditCard.Id;
                                    CreditCard.Info.Number = booking.PaymentInfo.CreditCard.Info.Number;
                                    CreditCard.Info.CVC = booking.PaymentInfo.CreditCard.Info.CVC;
                                    db.AssociationUserCreditCardInfoes.ApplyChanges(CreditCard.Info);

                                    booking.PaymentInfo.CreditCard.SavedCreditCardId = CreditCard.Id;
                                    db.BookingPaymentCreditCards.ApplyChanges(booking.PaymentInfo.CreditCard);
                                    db.SaveChanges();
                                }

                                //make default billing
                                if (booking.PaymentInfo.CreditCard.SavedCrediCardIsDefaultBilling && booking.PaymentInfo.CreditCard.SavedCreditCardId != 0)
                                {
                                    var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == booking.PaymentInfo.AssociationUserId);
                                    if (defaultBilling != null && defaultBilling.CreditCardId != booking.PaymentInfo.CreditCard.SavedCreditCardId)
                                    {
                                        defaultBilling.BillingAccountId = null;
                                        defaultBilling.CreditCardId = booking.PaymentInfo.CreditCard.SavedCreditCardId;
                                    }
                                    else if (defaultBilling == null)
                                        defaultBilling = new AssociationUserDefaultBilling()
                                        {
                                            AssociationUserId = booking.PaymentInfo.AssociationUserId,
                                            CreditCardId = booking.PaymentInfo.CreditCard.SavedCreditCardId
                                        };

                                    db.AssociationUserDefaultBillings.ApplyChanges(defaultBilling);
                                    db.SaveChanges();
                                }
                            }
                            else if (booking.PaymentInfo.BillingAccount != null)
                            {
                                //add to saved billing
                                if (!string.IsNullOrWhiteSpace(booking.PaymentInfo.BillingAccount.SavedBillingAccountNickname) && booking.PaymentInfo.BillingAccount.SavedBillingAccountId == 0)
                                {
                                    var BillingAccount = new AssociationUserBillingAccount();
                                    BillingAccount.BillingAccountId = booking.PaymentInfo.BillingAccount.BillingAccountId;
                                    BillingAccount.BillingCode = booking.PaymentInfo.BillingAccount.BillingCode;
                                    BillingAccount.Email = booking.PaymentInfo.BillingAccount.Email;
                                    BillingAccount.ContactPerson = booking.PaymentInfo.BillingAccount.ContactPerson;
                                    BillingAccount.ContactNumber = booking.PaymentInfo.BillingAccount.ContactNumber;
                                    BillingAccount.Name = booking.PaymentInfo.BillingAccount.SavedBillingAccountNickname;
                                    db.AssociationUserBillingAccounts.ApplyChanges(BillingAccount);
                                    db.SaveChanges();

                                    booking.PaymentInfo.BillingAccount.SavedBillingAccountId = BillingAccount.Id;
                                    db.BookingPaymentBillingAccounts.ApplyChanges(booking.PaymentInfo.BillingAccount);
                                    db.SaveChanges();
                                }

                                //make default billing
                                if (booking.PaymentInfo.BillingAccount.SavedBillingAccountIsDefaultBilling && booking.PaymentInfo.BillingAccount.SavedBillingAccountId != 0)
                                {
                                    var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == booking.PaymentInfo.AssociationUserId);
                                    if (defaultBilling != null && defaultBilling.BillingAccountId != booking.PaymentInfo.BillingAccount.SavedBillingAccountId)
                                    {
                                        defaultBilling.CreditCardId = null;
                                        defaultBilling.BillingAccountId = booking.PaymentInfo.BillingAccount.SavedBillingAccountId;
                                    }
                                    else if (defaultBilling == null)
                                        defaultBilling = new AssociationUserDefaultBilling()
                                        {
                                            AssociationUserId = booking.PaymentInfo.AssociationUserId,
                                            BillingAccountId = booking.PaymentInfo.BillingAccount.SavedBillingAccountId
                                        };

                                    db.AssociationUserDefaultBillings.ApplyChanges(defaultBilling);
                                    db.SaveChanges();
                                }
                            }
                        }

                        string issuedBy = "";
                        if (HttpContext.Current.User.IsInRole(RoleName.StaffUser))
                            issuedBy = "LIMOBOOK / STAFF";
                        else if (HttpContext.Current.User.IsInRole(RoleName.Client))
                            issuedBy = "LIMOBOOK / ONLINE";

                        db.BookingDispatchings.ApplyChanges(
                            new BookingDispatching()
                            {
                                BookingId = booking.Id,
                                Status = DispatchingStatus.Waiting,
                                IssuedBy = issuedBy,
                                IssueDate = DateTime.UtcNow
                            }
                        );
                        db.SaveChanges();

                        //remove original booking
                        if (booking.OriginalId != 0)
                        {
                            db.Bookings.Where(b => b.Id == booking.OriginalId).ForEach(b => db.Bookings.DeleteObject(b));
                            db.SaveChanges();
                        }

                        var paymentApi = PaymentApi.Get(CurrentAssociationId);
                        db.BookingTransactionCreditCards.IncludeAll("Info").Where(t => t.BookingId == booking.Id && t.OrderDateTime == null).ForEach(t =>
                        {
                            t.PaymentApi = paymentApi.Name;
                            t.OrderNumber = booking.Id + "_" + DateTime.UtcNow.ToString("HHmmss");
                            t.OrderDateTime = DateTime.UtcNow;
                            db.BookingTransactionCreditCards.ApplyChanges(t);
                            db.SaveChanges();

                            //capture money
                            if (t.OrderType == OrderType.Capture)
                                paymentApi.Capture(t.Info.Number, t.Info.CVC, t.ExpiryYear, t.ExpiryMonth, t.OrderAmount, t.OrderNumber);
                            else if (t.OrderType == OrderType.Refund)
                                paymentApi.Refund(t.Info.Number, t.Info.CVC, t.ExpiryYear, t.ExpiryMonth, t.OrderAmount, t.OrderNumber, t.OriginalOrderNumber);
                        });

                        transaction.Commit();
                        return response;
                    }
                }
            }
            catch (PaymentApiException ex)
            {
                var response = new SubmitBookingResponse();
                response.AddError("CreditCard", ex.ToString());
                return response;
            }
            catch (Exception ex)
            {
                var response = new SubmitBookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Пример #4
0
 private void UpdateSelectedProfileBilling(AssociationUserCreditCard creditCard, AssociationUserBillingAccount billingAccount)
 {
     SelectedProfileBilling = null;
     if (creditCard != null)
         //SelectedProfileBilling = string.Format("Tax Invoice:\n {0}", taxInvoice.Name);
         SelectedProfileBilling = string.Format("{0}\n{1}\n{2}   {3:00}/{4:00}", creditCard.Type.ToString(), creditCard.Holder, creditCard.Number, creditCard.ExpiryMonth, creditCard.ExpiryYear % 100);
     else if (billingAccount != null)
         //SelectedProfileBilling = string.Format("Billing Account:\n {0}", BillingAccount.Name);
         SelectedProfileBilling = string.Format("{0}\n{1} {2} {3} {4}\n{5}", billingAccount.BillingAccount.Name, billingAccount.BillingAccount.SuburbName, billingAccount.BillingAccount.State, billingAccount.BillingAccount.SuburbCode, billingAccount.BillingAccount.Country.Abbreviation2, billingAccount.BillingCode);
     OnPropertyChanged(() => SelectedProfileBilling);
 }
Пример #5
0
        public void RemoveUserBillingAccount(int billingAccountId)
        {
            using (var db = new LomsContext())
            {
                db.Connection.Open();

                using (var transaction = db.Connection.BeginTransaction())
                {
                    var query = from cb in db.AssociationUserBillingAccounts
                                join b in db.AssociationUserDefaultBillings on cb.Id equals b.BillingAccountId
                                where b.BillingAccountId == billingAccountId 
                                select b;

                    var defaultBilling = query.FirstOrDefault();
                    if (defaultBilling != null)
                        db.AssociationUserDefaultBillings.DeleteObject(defaultBilling);

                    var billingAccount = new AssociationUserBillingAccount() { Id = billingAccountId };
                    db.AssociationUserBillingAccounts.Attach(billingAccount);
                    db.AssociationUserBillingAccounts.DeleteObject(billingAccount);
                    db.SaveChanges();

                    transaction.Commit();
                }
            }
        }
Пример #6
0
        public AssociationUserBillingAccount SaveUserBillingAccount(AssociationUserBillingAccount billingAccount)
        {
            using (var db = new LomsContext())
            {
                db.Connection.Open();

                using (var transaction = db.Connection.BeginTransaction())
                {
                    db.AssociationUserBillingAccounts.ApplyChanges(billingAccount);
                    db.SaveChanges();

                    if (billingAccount.IsDefaultBilling)
                    {
                        var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == billingAccount.AssociationUserId);
                        if (defaultBilling != null && defaultBilling.BillingAccountId != billingAccount.Id)
                        {
                            defaultBilling.BillingAccountId = billingAccount.Id;
                            defaultBilling.CreditCardId = null;
                        }
                        else if (defaultBilling == null)
                            defaultBilling = new AssociationUserDefaultBilling() { AssociationUserId = billingAccount.AssociationUserId, BillingAccountId = billingAccount.Id };

                        db.AssociationUserDefaultBillings.ApplyChanges(defaultBilling);
                        db.SaveChanges();
                    }

                    transaction.Commit();
                }
            }

            using (var db = new LomsContext())
            {
                billingAccount = db.AssociationUserBillingAccounts.IncludeAll("BillingAccount", "BillingAccount.Country").FirstOrDefault(a => a.Id == billingAccount.Id);
                billingAccount.IsDefaultBilling = 0 != db.AssociationUserDefaultBillings.Count(b => b.AssociationUserId == billingAccount.AssociationUserId && b.BillingAccountId == billingAccount.Id);

                return billingAccount;
            }

        }
     public bool Equals(AssociationUserBillingAccount other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.Id == 0 && Id == 0)
 			return false;
 		else
 			return other.Id == Id;
     }
     private void FixupBillingAccount(AssociationUserBillingAccount previousValue, bool skipKeys = false)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (BillingAccount != null)
         {
             BillingAccountId = BillingAccount.Id;
         }
 
         else if (!skipKeys)
         {
             BillingAccountId = null;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("BillingAccount")
                 && (ChangeTracker.OriginalValues["BillingAccount"] == BillingAccount))
             {
                 ChangeTracker.OriginalValues.Remove("BillingAccount");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("BillingAccount", previousValue);
             }
             if (BillingAccount != null && !BillingAccount.ChangeTracker.ChangeTrackingEnabled)
             {
                 BillingAccount.StartTracking();
             }
         }
     }
 public NewBillingAccountViewModel()
 {
     SavedBillingAccount = new AssociationUserBillingAccount();
     SavedBillingAccount.SupressValidationOnPropertyChanges = true;
 }