/// <summary> /// Called when an Agreement is being added /// </summary> /// <param name="sender">The grid that is sending the insert command</param> /// <param name="e">The Command Event Arguments</param> protected void rgAgreements_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { //Add metrics var metric = new MetricHandler(customer.OrgCode, customer.CustomerID, null, MetricType.RecordAdded, "Agreement", "Agreement Added"); metric.SubmitChanges(); //Cast the GridCommandEventArgs item as an editable item GridEditableItem editedItem = e.Item as GridEditableItem; //Find the user control used by that item save it as a UserControl UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); //Create a new Agreement object var agreement = new Agreement(); //Create a new mod object var mod = new AgreementMod(); //Assign the values from the user control GrabValuesFromUserControl(userControl, ref agreement, ref mod); //Set Agreement End date equal to that from the mod 0 agreement.EndDate = mod.EndDate; //Add the mod to the agreement agreement.AgreementMods.Add(mod); //Add the Agreement to the Customer customer.Agreements.Add(agreement); //Add the agreement to the agreements table siftaDB.Agreements.InsertOnSubmit(agreement); //Submit changes to the database siftaDB.SubmitChanges(); //Update Records with Unique Record ID's RecordIdentifiers.UpdateRecords(); }
/// <summary> /// Called to copy an agreement 1 fiscal year ahead /// </summary> /// <param name="agreement">The agreement to be copied</param> protected void CopyAgreement(Agreement agreement) { //Add metrics var metric = new MetricHandler(customer.OrgCode, customer.CustomerID, null, MetricType.RecordCopied, "Agreement", String.Format("Copied AgreemendID = {0}", agreement.AgreementID)); metric.SubmitChanges(); //Grabs Mod 0 for the Agreement (the original agreement information is what we are copying over) var mod = agreement.AgreementMods.FirstOrDefault(p => p.Number == 0); //Grabs the list of Site funding for the original mod var siteFunding = mod.FundingSites.ToList(); //Grab all coop funding for mod 0; var coopFunding = mod.CooperativeFundings.ToList(); //Grabs the list of studies funding for the original mod var studiesFunding = mod.FundingStudies.ToList(); //Grab list of account fund sources var accFundSrc = siftaDB.AccountFundSources.Where(x => x.AgreementModID == mod.AgreementModID).ToList(); //Create a new mod var copyMod = new AgreementMod(); //Create a new Agreement and assign it values from the old one var copy = new Agreement() { BillingCycleFrequency = agreement.BillingCycleFrequency, PurchaseOrderNumber = agreement.PurchaseOrderNumber + "_Copy", FundsType = agreement.FundsType, Remarks = agreement.Remarks, CustomerBillingContact = agreement.CustomerBillingContact, CustomerTechnicalContact = agreement.CustomerTechnicalContact, Customer2Group = agreement.Customer2Group, USGSBillingContact = agreement.USGSBillingContact, USGSTechnicalContact = agreement.USGSTechnicalContact, CreatedBy = user.ID, CreatedDate = DateTime.Now, ModifiedBy = user.ID, ModifiedDate = DateTime.Now }; //The Start date needs to be pushed up a year if it isn't null if (mod.StartDate != null) { //Set the start date for the agreement to 1 year after the previous agreements start date copy.StartDate = Convert.ToDateTime(mod.StartDate).AddYears(1); } else { copy.StartDate = null; } //The End date needs to be pushed up a year if it isn't null if (mod.EndDate != null) { //Set the end date for the agreement to 1 year after the previous agreements end date copy.EndDate = Convert.ToDateTime(mod.EndDate).AddYears(1); } else { copy.EndDate = null; } //Set the Mods Start and End Date to be the one from the copied Agreement copyMod.StartDate = copy.StartDate; copyMod.EndDate = copy.EndDate; //Assign values from old mod to new mod copyMod.FundingUSGSCMF = mod.FundingUSGSCMF; copyMod.FundingCustomer = mod.FundingCustomer; copyMod.FundingOther = mod.FundingOther; copyMod.FundingOtherReason = mod.FundingOtherReason; copyMod.Number = 0; copyMod.Remarks = mod.Remarks; copyMod.CreatedBy = copyMod.ModifiedBy = user.ID; copyMod.CreatedDate = copyMod.ModifiedDate = DateTime.Now; //Add Site Funding to copy mod foreach (var siteF in siteFunding) { copyMod.FundingSites.Add(new FundingSite() { AgencyCode = siteF.AgencyCode, CollectionCodeID = siteF.CollectionCodeID, DifficultyFactor = siteF.DifficultyFactor, DifficultyFactorReason = siteF.DifficultyFactorReason, FundingCustomer = siteF.FundingCustomer, FundingUSGSCMF = siteF.FundingUSGSCMF, CollectionUnits = siteF.CollectionUnits, SiteNumber = siteF.SiteNumber, StartDate = siteF.StartDate?.AddYears(1), EndDate = siteF.EndDate?.AddYears(1), Remarks = siteF.Remarks, CreatedBy = user.ID, CreatedDate = DateTime.Now, ModifiedBy = user.ID, ModifiedDate = DateTime.Now }); } //Add Studies Funding to the copyMod foreach (var studiesF in studiesFunding) { copyMod.FundingStudies.Add(new FundingStudy() { BasisProjectNumber = studiesF.BasisProjectNumber, ResearchCodeID = studiesF.ResearchCodeID, Units = studiesF.Units, Remarks = studiesF.Remarks, FundingCustomer = studiesF.FundingCustomer, FundingUSGSCMF = studiesF.FundingUSGSCMF, StartDate = studiesF.StartDate?.AddYears(1), EndDate = studiesF.EndDate?.AddYears(1), CreatedBy = user.ID, CreatedDate = DateTime.Now, ModifiedBy = user.ID, ModifiedDate = DateTime.Now }); } //Add Copied Mod to the copied agreement copy.AgreementMods.Add(copyMod); //Add copied agreement to the customer customer.Agreements.Add(copy); //Submit changes to the database siftaDB.SubmitChanges(); //Add the cooperative funding to the new agreement mod foreach (var cfunding in coopFunding) { copyMod.CooperativeFundings.Add(new CooperativeFunding() { AccountNumber = cfunding.AccountNumber, AgreementID = copy.AgreementID, CreatedBy = user.ID, CreatedDate = DateTime.Now, ModifiedBy = user.ID, ModifiedDate = DateTime.Now, Remarks = cfunding.Remarks, Status = "LOW", ModNumber = cfunding.ModNumber, FiscalYear = Convert.ToInt32(cfunding.FiscalYear) + 1, FundingCustomer = cfunding.FundingCustomer, FundingUSGSCMF = cfunding.FundingUSGSCMF }); } siftaDB.SubmitChanges(); foreach (var accFund in accFundSrc) { var newFund = new AccountFundSource(); newFund.AgreementModID = copyMod.AgreementModID; newFund.FundSourceFY = accFund.FundSourceFY + 1; newFund.AccountNumber = accFund.AccountNumber; newFund.CustomerClass = accFund.CustomerClass; newFund.MatchPair = accFund.MatchPair; newFund.ProgramElementCode = accFund.ProgramElementCode; newFund.Funding = accFund.Funding; newFund.FundStatus = "LOW"; newFund.Remarks = accFund.Remarks; newFund.CreatedBy = user.ID; newFund.CreatedDate = DateTime.Now; newFund.ModifiedBy = user.ID; newFund.ModifiedDate = DateTime.Now; siftaDB.AccountFundSources.InsertOnSubmit(newFund); } siftaDB.SubmitChanges(); //Update Records with Unique Record ID's RecordIdentifiers.UpdateRecords(); //Rebind the agreement grid rgAgreements.Rebind(); }