Esempio n. 1
0
        public void SaveHistory(Enums.HistoryType ct, PaymentCharge original, string uid)
        {
            History h = new History();

            h.ObjectTypeName = this.GetType().ToString();
            h.Identifier     = ChargeID;
            h.OrganizationID = Requisition.OrganizationID;
            h.ChangeType     = ct;
            h.Active         = true;

            switch (ct)
            {
            case org.secc.Purchasing.Enums.HistoryType.ADD:
                h.OriginalXML = null;
                h.UpdatedXML  = Serialize(this);
                break;

            case org.secc.Purchasing.Enums.HistoryType.UPDATE:
                h.OriginalXML = Serialize(original);
                h.UpdatedXML  = Serialize(this);
                break;

            case org.secc.Purchasing.Enums.HistoryType.DELETE:
                h.OriginalXML = Serialize(this);
                h.UpdatedXML  = null;
                break;
            }

            h.Save(uid);
        }
Esempio n. 2
0
        public void Save(string uid)
        {
            try
            {
                if (String.IsNullOrEmpty(uid))
                {
                    throw new ArgumentNullException("uid", "User ID is required.");
                }

                Dictionary <string, string> ValErrors = Validate();
                if (ValErrors.Count > 0)
                {
                    throw new RequisitionNotValidException("Payment Charge is not valid.", ValErrors);
                }

                using (PurchasingContext Context = ContextHelper.GetDBContext())
                {
                    Enums.HistoryType ChangeType;
                    PaymentCharge     Original = null;
                    PaymentChargeData Data     = null;

                    if (ChargeID == 0)
                    {
                        ChangeType = Enums.HistoryType.ADD;

                        Data              = new PaymentChargeData();
                        Data.created_by   = uid;
                        Data.date_created = DateTime.Now;
                    }
                    else
                    {
                        ChangeType = Enums.HistoryType.UPDATE;
                        Data       = Context.PaymentChargeDatas.FirstOrDefault(x => x.charge_id == ChargeID);
                        Original   = new PaymentCharge(Data);
                    }

                    Data.payment_id        = PaymentID;
                    Data.requisition_id    = RequisitionID;
                    Data.company_id        = CompanyID;
                    Data.fund_id           = FundID;
                    Data.department_id     = DepartmentID;
                    Data.account_id        = AccountID;
                    Data.project_id        = ProjectID;
                    Data.fiscal_year_start = FYStartDate;
                    Data.amount            = Amount;
                    Data.modified_by       = uid;
                    Data.date_modified     = DateTime.Now;
                    Data.active            = Active;

                    if (ChargeID == 0)
                    {
                        Context.PaymentChargeDatas.InsertOnSubmit(Data);
                    }

                    Context.SubmitChanges();
                    Load(Data);

                    SaveHistory(ChangeType, Original, uid);
                }
            }
            catch (Exception ex)
            {
                throw new RequisitionException("An error has occurred while saving payment charge.", ex);
            }
        }