Ejemplo n.º 1
0
        public static Common.Models.Matters.Matter Edit(Common.Models.Matters.Matter model,
                                                        Common.Models.Account.Users modifier)
        {
            model.ModifiedBy = modifier;
            model.Modified   = DateTime.UtcNow;
            List <Common.Models.Matters.MatterContact> leadAttorneyMatches;

            DBOs.Matters.Matter dbo = Mapper.Map <DBOs.Matters.Matter>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("UPDATE \"matter\" SET \"matter_type_id\"=@MatterTypeId, " +
                             "\"title\"=@Title, \"active\"=@Active, \"parent_id\"=@ParentId, \"synopsis\"=@Synopsis, \"utc_modified\"=@UtcModified, " +
                             "\"minimum_charge\"=@MinimumCharge, \"estimated_charge\"=@EstimatedCharge, \"maximum_charge\"=@MaximumCharge, " +
                             "\"default_billing_rate_id\"=@DefaultBillingRateId, \"billing_group_id\"=@BillingGroupId, \"override_matter_rate_with_employee_rate\"=@OverrideMatterRateWithEmployeeRate, " +
                             "\"modified_by_user_pid\"=@ModifiedByUserPId, \"jurisdiction\"=@Jurisdiction, \"case_number\"=@CaseNumber, \"lead_attorney_contact_id\"=@LeadAttorneyContactId, \"bill_to_contact_id\"=@BillToContactId " +
                             "WHERE \"id\"=@Id", dbo);
            }

            leadAttorneyMatches = MatterContact.ListForMatterByRole(dbo.Id, "Lead Attorney");

            if (leadAttorneyMatches.Count > 1)
            {
                throw new Exception("More than one Lead Attorney found.");
            }
            else if (leadAttorneyMatches.Count < 1)
            {   // Insert only
                MatterContact.Create(new Common.Models.Matters.MatterContact()
                {
                    Matter  = model,
                    Contact = new Common.Models.Contacts.Contact()
                    {
                        Id = dbo.LeadAttorneyContactId.Value
                    },
                    Role = "Lead Attorney"
                }, modifier);
            }
            else
            {   // Replace
                leadAttorneyMatches[0].Contact.Id = dbo.LeadAttorneyContactId.Value;
                MatterContact.Edit(leadAttorneyMatches[0], modifier);
            }

            return(model);
        }
Ejemplo n.º 2
0
        public static Common.Models.Matters.Matter Create(Common.Models.Matters.Matter model,
                                                          Common.Models.Account.Users creator)
        {
            // Matter
            if (!model.Id.HasValue)
            {
                model.Id = Guid.NewGuid();
            }
            model.CreatedBy = model.ModifiedBy = creator;
            model.Created   = model.Modified = DateTime.UtcNow;
            DBOs.Matters.Matter dbo = Mapper.Map <DBOs.Matters.Matter>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("INSERT INTO \"matter\" (\"id\", \"matter_type_id\", \"title\", \"active\", \"parent_id\", \"synopsis\", " +
                             "\"minimum_charge\", \"estimated_charge\", \"maximum_charge\", \"default_billing_rate_id\", \"billing_group_id\", \"override_matter_rate_with_employee_rate\", " +
                             "\"utc_created\", \"utc_modified\", " +
                             "\"created_by_user_pid\", \"modified_by_user_pid\", \"jurisdiction\", \"case_number\", \"lead_attorney_contact_id\", \"bill_to_contact_id\") " +
                             "VALUES (@Id, @MatterTypeId, @Title, @Active, @ParentId, @Synopsis, @MinimumCharge, @EstimatedCharge, @MaximumCharge, @DefaultBillingRateId, @BillingGroupId, @OverrideMatterRateWithEmployeeRate, " +
                             "@UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId, " +
                             "@Jurisdiction, @CaseNumber, @LeadAttorneyContactId, @BillToContactId)",
                             dbo);
            }

            MatterContact.Create(new Common.Models.Matters.MatterContact()
            {
                Matter  = model,
                Contact = new Common.Models.Contacts.Contact()
                {
                    Id = dbo.LeadAttorneyContactId.Value
                },
                Role = "Lead Attorney"
            }, creator);

            return(model);
        }