示例#1
0
        public static Common.Models.Notes.NoteMatter Create(Common.Models.Notes.NoteMatter model,
                                                            Common.Models.Account.Users creator)
        {
            if (!model.Id.HasValue)
            {
                model.Id = Guid.NewGuid();
            }
            model.Created   = model.Modified = DateTime.UtcNow;
            model.CreatedBy = model.ModifiedBy = creator;
            DBOs.Notes.NoteMatter dbo = Mapper.Map <DBOs.Notes.NoteMatter>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                Common.Models.Notes.NoteMatter currentModel = Get(model.Matter.Id.Value, model.Note.Id.Value);

                if (currentModel != null)
                { // Update
                    conn.Execute("UPDATE \"note_matter\" SET \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " +
                                 "\"utc_disabled\"=null, \"disabled_by_user_pid\"=null WHERE \"id\"=@Id", dbo);
                    model.Created   = currentModel.Created;
                    model.CreatedBy = currentModel.CreatedBy;
                }
                else
                { // Create
                    conn.Execute("INSERT INTO \"note_matter\" (\"id\", \"note_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                                 "VALUES (@Id, @NoteId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                                 dbo);
                }
            }

            return(model);
        }
示例#2
0
 public static Common.Models.Notes.NoteMatter Create(
     Transaction t,
     Common.Models.Notes.NoteMatter model,
     Common.Models.Account.Users creator)
 {
     return(Create(model, creator, t.Connection, false));
 }