Пример #1
0
        public static Common.Models.Documents.DocumentMatter Create(Common.Models.Documents.DocumentMatter model,
                                                                    Common.Models.Account.Users creator)
        {
            model.Created   = model.Modified = DateTime.UtcNow;
            model.CreatedBy = model.ModifiedBy = creator;
            DBOs.Documents.DocumentMatter dbo = Mapper.Map <DBOs.Documents.DocumentMatter>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                Common.Models.Documents.DocumentMatter currentModel = Get(model.Matter.Id.Value, model.Document.Id.Value);

                if (currentModel != null)
                { // Update
                    conn.Execute("UPDATE \"document_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 \"document_matter\" (\"id\", \"document_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                                 "VALUES (@Id, @DocumentId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                                 dbo);
                }
            }

            return(model);
        }
Пример #2
0
        public static Common.Models.Documents.DocumentMatter Create(Common.Models.Documents.DocumentMatter model,
                                                                    Common.Models.Account.Users creator,
                                                                    IDbConnection conn = null, bool closeConnection = true)
        {
            model.Created   = model.Modified = DateTime.UtcNow;
            model.CreatedBy = model.ModifiedBy = creator;
            DBOs.Documents.DocumentMatter dbo = Mapper.Map <DBOs.Documents.DocumentMatter>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            Common.Models.Documents.DocumentMatter currentModel = Get(model.Matter.Id.Value, model.Document.Id.Value, conn, false);

            if (currentModel != null)
            { // Update
                conn.Execute("UPDATE \"document_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
                if (conn.Execute("INSERT INTO \"document_matter\" (\"id\", \"document_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                                 "VALUES (@Id, @DocumentId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                                 dbo) > 0)
                {
                    model.Id = conn.Query <DBOs.Documents.DocumentMatter>("SELECT currval(pg_get_serial_sequence('document_matter', 'id')) AS \"id\"").Single().Id;
                }
            }

            DataHelper.Close(conn, closeConnection);

            return(model);
        }