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 CreditCardViewModel() { CreditCard = new AssociationUserCreditCard(); CreditCard.SupressValidationOnPropertyChanges = true; }
private void CreditCardAdded(AssociationUserCreditCard cc) { SelectCreditCardViewModel.CreditCards.Replace(cc); SelectCreditCardViewModel.SelectedCreditCard = cc; SelectedProcessIndex = 1; }
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); }
public bool Equals(AssociationUserCreditCard 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; }
public ValidateCreditCard(AssociationUserCreditCard card) { _card = card; }
public void RemoveCreditCard(int cardId) { using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { var query = from cc in db.AssociationUserCreditCards join b in db.AssociationUserDefaultBillings on cc.Id equals b.CreditCardId where b.CreditCardId == cardId select b; var defaultBilling = query.FirstOrDefault(); if (defaultBilling != null) { db.AssociationUserDefaultBillings.DeleteObject(defaultBilling); } var card = new AssociationUserCreditCard() { Id = cardId }; db.AssociationUserCreditCards.Attach(card); db.AssociationUserCreditCards.DeleteObject(card); db.SaveChanges(); transaction.Commit(); } } }
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; } }
public AssociationUserCreditCard SaveCreditCard(AssociationUserCreditCard card) { bool isAdd = card.Id == 0; using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { db.AssociationUserCreditCards.ApplyChanges(card); db.SaveChanges(); if (isAdd) { var info = new AssociationUserCreditCardInfo(); info.CardId = card.Id; info.Number = card.Number; info.CVC = card.CVC; db.AssociationUserCreditCardInfoes.ApplyChanges(info); db.SaveChanges(); } if (card.IsDefaultBilling) { var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == card.AssociationUserId); if (defaultBilling != null && defaultBilling.CreditCardId != card.Id) { defaultBilling.CreditCardId = card.Id; defaultBilling.BillingAccountId = null; } else if (defaultBilling == null) defaultBilling = new AssociationUserDefaultBilling() { AssociationUserId = card.AssociationUserId, CreditCardId = card.Id }; db.AssociationUserDefaultBillings.ApplyChanges(defaultBilling); db.SaveChanges(); } if (isAdd) { try { var paymentApi = PaymentApi.Get(CurrentAssociationId); paymentApi.PreAuth(card.Number, card.CVC, card.ExpiryYear, card.ExpiryMonth, "cc" + card.Id + "_" + DateTime.UtcNow.ToString("HHmmss")); } catch (Exception ex) { card.AddError("Entity", ex.Message); return card; } } transaction.Commit(); } } using (var db = new LomsContext()) { card = db.AssociationUserCreditCards.IncludeAll("Info").FirstOrDefault(a => a.Id == card.Id); card.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(card.Info.Number); card.Info = null; card.IsDefaultBilling = 0 != db.AssociationUserDefaultBillings.Count(b => b.AssociationUserId == card.AssociationUserId && b.CreditCardId == card.Id); card.AcceptChanges(); return card; } }
private void OpenCreditCardDetailWindow(AssociationUserCreditCard creditCard, bool isAdd) { var viewModel = Kernel.Get<AddEditCreditCardViewModel>(); var view = Kernel.Get<AddEditCreditCardWindow>(); viewModel.IsAdd = isAdd; viewModel.CreditCard = creditCard; viewModel.ProfileId = SelectedProfile.Id; view.DataContext = viewModel; viewModel.Completed += (o, e) => { view.Close(); CreditCards.Replace(e.Value); SelectedCreditCard = e.Value; }; view.Show(); }
private void AddCreditCard() { var newCreditCard = new AssociationUserCreditCard(); OpenCreditCardDetailWindow(newCreditCard, true); }
private void FixupCreditCard(AssociationUserCreditCard previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (CreditCard != null) { CreditCardId = CreditCard.Id; } else if (!skipKeys) { CreditCardId = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("CreditCard") && (ChangeTracker.OriginalValues["CreditCard"] == CreditCard)) { ChangeTracker.OriginalValues.Remove("CreditCard"); } else { ChangeTracker.RecordOriginalValue("CreditCard", previousValue); } if (CreditCard != null && !CreditCard.ChangeTracker.ChangeTrackingEnabled) { CreditCard.StartTracking(); } } }
public AssociationUserCreditCard SaveCreditCard(AssociationUserCreditCard card) { bool isAdd = card.Id == 0; using (var db = new LomsContext()) { db.Connection.Open(); using (var transaction = db.Connection.BeginTransaction()) { db.AssociationUserCreditCards.ApplyChanges(card); db.SaveChanges(); if (isAdd) { var info = new AssociationUserCreditCardInfo(); info.CardId = card.Id; info.Number = card.Number; info.CVC = card.CVC; db.AssociationUserCreditCardInfoes.ApplyChanges(info); db.SaveChanges(); } if (card.IsDefaultBilling) { var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == card.AssociationUserId); if (defaultBilling != null && defaultBilling.CreditCardId != card.Id) { defaultBilling.BillingAccountId = null; defaultBilling.CreditCardId = card.Id; } else if (defaultBilling == null) defaultBilling = new AssociationUserDefaultBilling() { AssociationUserId = card.AssociationUserId, CreditCardId = card.Id }; db.AssociationUserDefaultBillings.ApplyChanges(defaultBilling); db.SaveChanges(); } transaction.Commit(); } } using (var db = new LomsContext()) { card = db.AssociationUserCreditCards.IncludeAll("Info").FirstOrDefault(a => a.Id == card.Id); card.Number = ObfuscateCreditCardNumber(card.Info.Number); card.Info = null; card.AcceptChanges(); return card; } }