private void Load(PaymentCreditCardData data) { Init(); if (data != null) { mCreditCardID = data.credit_card_id; mCardLastFour = data.card_last_four; mCardExpirationDate = data.card_expiration_date; if (data.card_holder_id == null) { mCardholderID = 0; } else { mCardholderID = (int)data.card_holder_id; } mCreatedByUserID = data.created_by; mModifiedByUserID = data.modified_by; mDateCreated = data.date_created; if (data.date_modified == null) { mDateModified = DateTime.MinValue; } else { mDateModified = (DateTime)data.date_modified; } mActive = data.active; } }
public CreditCard(PaymentCreditCardData data) { Load(data); }
public void Save(string uid) { try { Dictionary <string, string> ValErrors = Validate(); if (ValErrors.Count > 0) { throw new RequisitionNotValidException("Payment Method is not valid.", ValErrors); } HistoryType UpdateType; PaymentMethod Original = null; using (PurchasingContext Context = ContextHelper.GetDBContext()) { PaymentMethodData Data = new PaymentMethodData(); if (PaymentMethodID == 0) { UpdateType = HistoryType.ADD; Data = new PaymentMethodData(); Data.date_created = DateTime.Now; Data.created_by = uid; Data.organization_id = 1; } else { Data = Context.PaymentMethodDatas.Where(x => x.payment_method_id == PaymentMethodID).FirstOrDefault(); Original = new PaymentMethod(Data); UpdateType = HistoryType.UPDATE; } Data.name = Name; if (String.IsNullOrEmpty(Description)) { Data.description = null; } else { Data.description = Description; } Data.date_modified = DateTime.Now; Data.modified_by = uid; Data.active = Active; if (CreditCard != null) { if (Data.PaymentCreditCardData == null) { Data.PaymentCreditCardData = new PaymentCreditCardData(); Data.PaymentCreditCardData.created_by = uid; Data.PaymentCreditCardData.date_created = DateTime.Now; } Data.PaymentCreditCardData.card_last_four = CreditCard.CardLastFour; Data.PaymentCreditCardData.card_expiration_date = CreditCard.CardExpirationDate; Data.PaymentCreditCardData.card_holder_id = CreditCard.CardHolderID; Data.PaymentCreditCardData.modified_by = uid; Data.PaymentCreditCardData.date_modified = DateTime.Now; } else { if (Data.PaymentCreditCardData != null) { PaymentCreditCardData CC = Data.PaymentCreditCardData; CC.active = false; CC.date_modified = DateTime.Now; CC.modified_by = uid; Data.PaymentCreditCardData = null; } } if (PaymentMethodID == 0) { Context.PaymentMethodDatas.InsertOnSubmit(Data); } Context.SubmitChanges(); Load(Data); SaveHistory(UpdateType, Original, uid); } } catch (Exception ex) { throw new PaymentMethodException("An error has occurred while saving Payment Method", ex); } }