public ActionResult Edit(int id, ViewModels.Matters.CourtGeographicalJurisdictionViewModel viewModel) { Common.Models.Account.Users currentUser; Common.Models.Matters.CourtGeographicalJurisdiction model; using (Data.Transaction trans = Data.Transaction.Create(true)) { try { currentUser = Data.Account.Users.Get(trans, User.Identity.Name); model = Mapper.Map <Common.Models.Matters.CourtGeographicalJurisdiction>(viewModel); model = Data.Matters.CourtGeographicalJurisdiction.Edit(trans, model, currentUser); trans.Commit(); return(RedirectToAction("Index")); } catch { trans.Rollback(); return(Edit(id)); } } }
public ActionResult Convert(long id) { List <ViewModels.Billing.BillingRateViewModel> billingRateList; List <ViewModels.Billing.BillingGroupViewModel> billingGroupList; List <ViewModels.Matters.MatterTypeViewModel> matterTypeList; List <ViewModels.Matters.CourtTypeViewModel> courtTypeList; List <ViewModels.Matters.CourtGeographicalJurisdictionViewModel> courtGeographicalJurisdictionList; List <ViewModels.Matters.CourtSittingInCityViewModel> courtSittingInCityList; List <ViewModels.Leads.LeadStatusViewModel> leadStatusList = new List <ViewModels.Leads.LeadStatusViewModel>(); List <ViewModels.Leads.LeadSourceViewModel> leadSourceList = new List <ViewModels.Leads.LeadSourceViewModel>(); List <ViewModels.Opportunities.OpportunityStageViewModel> opportunityStageList = new List <ViewModels.Opportunities.OpportunityStageViewModel>(); ViewModels.Opportunities.CreateOpportunityViewModel viewModel = new ViewModels.Opportunities.CreateOpportunityViewModel(); Common.Models.Opportunities.Opportunity opportunity; billingRateList = new List <ViewModels.Billing.BillingRateViewModel>(); billingGroupList = new List <ViewModels.Billing.BillingGroupViewModel>(); matterTypeList = new List <ViewModels.Matters.MatterTypeViewModel>(); courtTypeList = new List <ViewModels.Matters.CourtTypeViewModel>(); courtGeographicalJurisdictionList = new List <ViewModels.Matters.CourtGeographicalJurisdictionViewModel>(); courtSittingInCityList = new List <ViewModels.Matters.CourtSittingInCityViewModel>(); using (IDbConnection conn = Data.Database.Instance.GetConnection()) { opportunity = Data.Opportunities.Opportunity.Get(id, conn, false); opportunity.Lead = Data.Leads.Lead.Get(opportunity.Lead.Id.Value, conn, false); if (opportunity.Lead.Fee != null && opportunity.Lead.Fee.Id.HasValue) { opportunity.Lead.Fee = Data.Leads.LeadFee.Get(opportunity.Lead.Fee.Id.Value, conn, false); if (opportunity.Lead.Fee.To != null && opportunity.Lead.Fee.To.Id.HasValue) { opportunity.Lead.Fee.To = Data.Contacts.Contact.Get(opportunity.Lead.Fee.To.Id.Value, conn, false); } } opportunity.Lead.Contact = Data.Contacts.Contact.Get(opportunity.Lead.Contact.Id.Value, conn, false); opportunity.Lead.Source = Data.Leads.LeadSource.Get(opportunity.Lead.Source.Id.Value, conn, false); if (opportunity.Lead.Source.Type != null && opportunity.Lead.Source.Type.Id.HasValue) { opportunity.Lead.Source.Type = Data.Leads.LeadSourceType.Get(opportunity.Lead.Source.Type.Id.Value, conn, false); } opportunity.Lead.Status = Data.Leads.LeadStatus.Get(opportunity.Lead.Status.Id.Value, conn, false); opportunity.Account = Data.Contacts.Contact.Get(opportunity.Account.Id.Value, conn, false); opportunity.Stage = Data.Opportunities.OpportunityStage.Get(opportunity.Stage.Id.Value, conn, false); if (opportunity.Matter != null && opportunity.Matter.Id.HasValue) { opportunity.Matter = Data.Matters.Matter.Get(opportunity.Matter.Id.Value, conn, false); } // Tweaks // Probability is stored as a decimal (<1) need to change representation to percent opportunity.Probability *= 100; viewModel.Opportunity = Mapper.Map <ViewModels.Opportunities.OpportunityViewModel>(opportunity); viewModel.Opportunity.Lead = Mapper.Map <ViewModels.Leads.LeadViewModel>(opportunity.Lead); if (opportunity.Lead.Fee != null) { viewModel.Opportunity.Lead.Fee = Mapper.Map <ViewModels.Leads.LeadFeeViewModel>(opportunity.Lead.Fee); if (opportunity.Lead.Fee.To != null) { viewModel.Opportunity.Lead.Fee.To = Mapper.Map <ViewModels.Contacts.ContactViewModel>(opportunity.Lead.Fee.To); } else { viewModel.Opportunity.Lead.Fee.To = new ViewModels.Contacts.ContactViewModel(); } } else { viewModel.Opportunity.Lead.Fee = new ViewModels.Leads.LeadFeeViewModel(); viewModel.Opportunity.Lead.Fee.To = new ViewModels.Contacts.ContactViewModel(); } viewModel.Opportunity.Lead.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(opportunity.Lead.Contact); viewModel.Opportunity.Lead.Source = Mapper.Map <ViewModels.Leads.LeadSourceViewModel>(opportunity.Lead.Source); if (opportunity.Lead.Source.Type != null) { viewModel.Opportunity.Lead.Source.Type = Mapper.Map <ViewModels.Leads.LeadSourceTypeViewModel>(opportunity.Lead.Source.Type); } viewModel.Opportunity.Lead.Status = Mapper.Map <ViewModels.Leads.LeadStatusViewModel>(opportunity.Lead.Status); viewModel.Opportunity.Account = Mapper.Map <ViewModels.Contacts.ContactViewModel>(opportunity.Account); viewModel.Opportunity.Stage = Mapper.Map <ViewModels.Opportunities.OpportunityStageViewModel>(opportunity.Stage); if (opportunity.Matter != null) { return(RedirectToAction("Details", "Matters", new { id = opportunity.Matter.Id.Value })); } viewModel.Opportunity.Contacts = new List <ViewModels.Contacts.ContactViewModel>(); Data.Opportunities.OpportunityContact.ListForOpportunity(id, conn, false).ForEach(x => { viewModel.Opportunity.Contacts.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(x.Contact.Id.Value))); }); for (int i = 0; i < (20 - viewModel.Opportunity.Contacts.Count); i++) { viewModel.Opportunity.Contacts.Add(new ViewModels.Contacts.ContactViewModel()); } // Matter viewModel.Matter = new ViewModels.Matters.MatterViewModel() { Active = true, OverrideMatterRateWithEmployeeRate = true }; Data.Leads.LeadStatus.List(conn, false).ForEach(x => { leadStatusList.Add(Mapper.Map <ViewModels.Leads.LeadStatusViewModel>(x)); }); Data.Leads.LeadSource.List(conn, false).ForEach(x => { leadSourceList.Add(Mapper.Map <ViewModels.Leads.LeadSourceViewModel>(x)); }); Data.Opportunities.OpportunityStage.List(conn, false).ForEach(x => { opportunityStageList.Add(Mapper.Map <ViewModels.Opportunities.OpportunityStageViewModel>(x)); }); Data.Billing.BillingRate.List(conn, false).ForEach(x => { ViewModels.Billing.BillingRateViewModel vm = Mapper.Map <ViewModels.Billing.BillingRateViewModel>(x); vm.Title += " (" + vm.PricePerUnit.ToString("C") + ")"; billingRateList.Add(vm); }); Data.Billing.BillingGroup.List(conn, false).ForEach(x => { ViewModels.Billing.BillingGroupViewModel vm = Mapper.Map <ViewModels.Billing.BillingGroupViewModel>(x); vm.Title += " (" + vm.Amount.ToString("C") + ")"; billingGroupList.Add(vm); }); Data.Matters.MatterType.List(conn, false).ForEach(x => { ViewModels.Matters.MatterTypeViewModel vm = Mapper.Map <ViewModels.Matters.MatterTypeViewModel>(x); matterTypeList.Add(vm); }); Data.Matters.CourtType.List(conn, false).ForEach(x => { ViewModels.Matters.CourtTypeViewModel vm = Mapper.Map <ViewModels.Matters.CourtTypeViewModel>(x); courtTypeList.Add(vm); }); Data.Matters.CourtGeographicalJurisdiction.List(conn, false).ForEach(x => { ViewModels.Matters.CourtGeographicalJurisdictionViewModel vm = Mapper.Map <ViewModels.Matters.CourtGeographicalJurisdictionViewModel>(x); courtGeographicalJurisdictionList.Add(vm); }); Data.Matters.CourtSittingInCity.List(conn, false).ForEach(x => { ViewModels.Matters.CourtSittingInCityViewModel vm = Mapper.Map <ViewModels.Matters.CourtSittingInCityViewModel>(x); courtSittingInCityList.Add(vm); }); } ViewBag.BillingRateList = billingRateList; ViewBag.BillingGroupList = billingGroupList; ViewBag.MatterTypeList = matterTypeList; ViewBag.CourtTypeList = courtTypeList; ViewBag.CourtGeographicalJurisdictionList = courtGeographicalJurisdictionList; ViewBag.CourtSittingInCityList = courtSittingInCityList; ViewBag.LeadStatusList = leadStatusList; ViewBag.LeadSourceList = leadSourceList; ViewBag.StageList = opportunityStageList; return(View(viewModel)); }