public List <Agency> GetAgencyContactsByAgencyId(int agencyid) { var result = new List <Agency>(); var qry = _db.Agencies.Where(q => q.AgencyId == agencyid).OrderBy(q => q.FirstName); foreach (var q in qry) { var n = new Agency(); n.AgencyId = q.AgencyId; n.FirstName = q.FirstName; n.LastName = q.LastName; n.Address = q.Address; n.Phone = q.Phone; n.Salutation = q.Salutation; n.Fax = q.Fax; result.Add(n); } return(result); }
protected void AgencyButtonClicked(object sender, RadToolBarEventArgs e) { if (e.Item.Text == @"New") { RadGridAgency.SelectedIndexes.Clear(); ResetForm(); } else if (e.Item.Text == @"Update" && RadGridAgency.SelectedValue != null) { if (IsValid) { var cAgency = new CAgency(); var agc = cAgency.Get(Convert.ToInt32(RadGridAgency.SelectedValue)); var oriBasicCommission = Convert.ToDouble(agc.CommissionRateBasic); var oriSeasonalCommission = Convert.ToDouble(agc.CommissionRateSeasonal); var oriCreditLimit = Convert.ToDouble(agc.CreditLimit); agc.Name = RadComboBoxAgencyName.Text; agc.Abbreviation = tbAgencyShortName.Text; agc.GroupName = tbAgencyGroupName.Text; agc.PrintingName = tbAgencyPrintName.Text; agc.AgencyType = tbAgencyType.Text; agc.CommissionRateBasic = tbCommissionRateBasic.Value; agc.CommissionRateSeasonal = tbCommissionRateSeason.Value; agc.CreditLimit = tbCreditLimit.Value; agc.Location = Convert.ToInt32(ddlBusinessLocation.SelectedValue); agc.MainTargetCountry = Convert.ToInt32(ddlMainTarget.SelectedValue); if (tbContractStart.SelectedDate != null) { agc.ContractStartDate = Convert.ToDateTime(tbContractStart.SelectedDate); } if (tbContractEnd.SelectedDate != null) { agc.ContractEndDate = Convert.ToDateTime(tbContractEnd.SelectedDate); } agc.APPaymentTerm = tbAPPayTerm.Text; agc.APPaymentMethod = tbAPPayMethod.Text; agc.APBillingType = tbAPBillingType.Text; agc.APPaymentPriority = tbAPPAymentPriority.Text; agc.APPaymentSchedule = tbAPPaySchedule.Text; agc.ARCollectionTerm = tbARCollectionTerm.Text; agc.ARType = tbARType.Text; agc.ARCollectionPriority = tbARCollection.Text; agc.ARCollectionSchedule = tbARCollectionSchedule.Text; agc.ARCollectionMethod = tbARCollectionMethod.Text; agc.AgencyRegNo = tbAgencyNo.Text; agc.Currency = tbCurrency.Text; agc.Comment = tbComment.Text; agc.AgencyId = agc.AgencyId; agc.FirstName = agFname.Text; agc.LastName = agLname.Text; agc.Salutation = agTitle.Text; agc.Phone = agPhone.Text; agc.Mobile = agMobile.Text; agc.Fax = agFax.Text; agc.PEmail = agPEmail.Text; agc.SEmail = agSEmail.Text; agc.Website = agWebsite.Text; agc.Address = agAddress.Text; agc.City = agCity.Text; agc.Province = agProvince.Text; agc.Postal = agPostal.Text; if (ddlAgencyCountry.SelectedValue != string.Empty) { agc.CountryId = Convert.ToInt32(ddlAgencyCountry.SelectedValue); } agc.FirstName1 = agFname1.Text; agc.LastName1 = agLname1.Text; agc.Salutation1 = agTitle1.Text; agc.Phone1 = agPhone1.Text; agc.Mobile1 = agMobile1.Text; agc.Fax1 = agFax1.Text; agc.PEmail1 = agPEmail1.Text; agc.SEmail1 = agSEmail1.Text; agc.Website1 = agWebsite1.Text; agc.Address1 = agAddress1.Text; agc.City1 = agCity1.Text; agc.Province1 = agProvince1.Text; agc.Postal1 = agPostal1.Text; if (ddlAgencyCountry1.SelectedValue != string.Empty) { agc.CountryId1 = Convert.ToInt32(ddlAgencyCountry1.SelectedValue); } agc.IsActive = RadButtonActive.Checked; agc.UpdatedId = CurrentUserId; agc.UpdatedDate = DateTime.Now; if (oriBasicCommission == tbCommissionRateBasic.Value && oriSeasonalCommission == tbCommissionRateSeason.Value && oriCreditLimit == tbCreditLimit.Value) { cAgency.Update(agc); } else { cAgency.Update(agc); var cHistory = new CAgencyCommissionHistory(); var history = new AgencyCommissionHistory(); history.AgencyId = agc.AgencyId; history.OriBasicCommission = oriBasicCommission; history.OriSeasonCommission = oriSeasonalCommission; history.OriCreditLimit = oriCreditLimit; history.ChBasicCommission = (double)agc.CommissionRateBasic; history.ChSeasonCommission = (double)agc.CommissionRateSeasonal; history.ChCreditLimit = (double)agc.CreditLimit; history.SiteLocationId = CurrentSiteLocationId; history.UpdatedDate = DateTime.Now; history.UpdatedId = CurrentUserId; cHistory.Add(history); } var cAgencySiteLocation = new CAgencySiteLocation(); cAgencySiteLocation.DelAgencySiteLocationList(Convert.ToInt32(RadGridAgency.SelectedValue)); foreach (var siteLocation in RadComboBoxSiteLocation.CheckedItems) { var agencySiteLocation = new AgencySiteLocation() { CreatedId = CurrentUserId, AgencyId = Convert.ToInt32(RadGridAgency.SelectedValue), SiteLocationId = Convert.ToInt32(siteLocation.Value), CreatedDate = DateTime.Now }; cAgencySiteLocation.Add(agencySiteLocation); } RadGridAgency.Rebind(); ShowMessage("Update Agency Info Successfully"); } } else if (e.Item.Text == @"Save") { if (IsValid) { var cAgency = new CAgency(); var agc = new Erp2016.Lib.Agency(); agc.Name = RadComboBoxAgencyName.Text; agc.Abbreviation = tbAgencyShortName.Text; agc.GroupName = tbAgencyGroupName.Text; agc.PrintingName = tbAgencyPrintName.Text; agc.AgencyType = tbAgencyType.Text; agc.CommissionRateBasic = tbCommissionRateBasic.Value; agc.CommissionRateSeasonal = tbCommissionRateSeason.Value; agc.CreditLimit = tbCreditLimit.Value; agc.Location = Convert.ToInt32(ddlBusinessLocation.SelectedValue); agc.MainTargetCountry = Convert.ToInt32(ddlMainTarget.SelectedValue); agc.ContractStartDate = (tbContractStart.SelectedDate == null) ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(tbContractStart.SelectedDate); agc.ContractEndDate = (tbContractEnd.SelectedDate == null) ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(tbContractEnd.SelectedDate); agc.APPaymentTerm = tbAPPayTerm.Text; agc.APPaymentMethod = tbAPPayMethod.Text; agc.APBillingType = tbAPBillingType.Text; agc.APPaymentPriority = tbAPPAymentPriority.Text; agc.APPaymentSchedule = tbAPPaySchedule.Text; agc.ARCollectionTerm = tbARCollectionTerm.Text; agc.ARType = tbARType.Text; agc.ARCollectionPriority = tbARCollection.Text; agc.ARCollectionSchedule = tbARCollectionSchedule.Text; agc.ARCollectionMethod = tbARCollectionMethod.Text; agc.AgencyRegNo = tbAgencyNo.Text; agc.Currency = tbCurrency.Text; agc.Comment = tbComment.Text; agc.ApprovalDate = DateTime.Now; agc.IsActive = RadButtonActive.Checked; agc.CreatedId = CurrentUserId; agc.CreatedDate = DateTime.Now; agc.AgencyId = agc.AgencyId; agc.FirstName = agFname.Text; agc.LastName = agLname.Text; agc.Salutation = agTitle.Text; agc.Phone = agPhone.Text; agc.Mobile = agMobile.Text; agc.Fax = agFax.Text; agc.PEmail = agPEmail.Text; agc.SEmail = agSEmail.Text; agc.Website = agWebsite.Text; agc.Address = agAddress.Text; agc.City = agAddress.Text; agc.Province = agProvince.Text; agc.Postal = agPostal.Text; if (ddlAgencyCountry.SelectedValue != string.Empty) { agc.CountryId = Convert.ToInt32(ddlAgencyCountry.SelectedValue); } agc.FirstName1 = agFname1.Text; agc.LastName1 = agLname1.Text; agc.Salutation1 = agTitle1.Text; agc.Phone1 = agPhone1.Text; agc.Mobile1 = agMobile1.Text; agc.Fax1 = agFax1.Text; agc.PEmail1 = agPEmail1.Text; agc.SEmail1 = agSEmail1.Text; agc.Website1 = agWebsite1.Text; agc.Address1 = agAddress1.Text; agc.City1 = agCity1.Text; agc.Province1 = agProvince1.Text; agc.Postal1 = agPostal1.Text; if (ddlAgencyCountry1.SelectedValue != string.Empty) { agc.CountryId1 = Convert.ToInt32(ddlAgencyCountry1.SelectedValue); } int agencyId = cAgency.Add(agc); if (agencyId > 0) { var cAgencySiteLocation = new CAgencySiteLocation(); cAgencySiteLocation.DelAgencySiteLocationList(agencyId); foreach (var siteLocation in RadComboBoxSiteLocation.CheckedItems) { var agencySiteLocation = new AgencySiteLocation() { CreatedId = CurrentUserId, AgencyId = agencyId, SiteLocationId = Convert.ToInt32(siteLocation.Value), CreatedDate = DateTime.Now }; cAgencySiteLocation.Add(agencySiteLocation); } RadGridAgency.Rebind(); ShowMessage("Add Agency Info Successfully"); } } else { ShowMessage("Failed To Add."); } } else if (e.Item.Text == "Old Agency Lookup") { RunClientScript("ShowAgencyOldInfoWindow();"); } }