Пример #1
0
 public static Common.Models.Notes.NoteTask Create(
     Transaction t,
     Common.Models.Notes.NoteTask model,
     Common.Models.Account.Users creator)
 {
     return(Create(model, creator, t.Connection, false));
 }
Пример #2
0
        public static Common.Models.Notes.NoteTask Create(Common.Models.Notes.NoteTask model,
                                                          Common.Models.Account.Users creator)
        {
            model.Created   = model.Modified = DateTime.UtcNow;
            model.CreatedBy = model.ModifiedBy = creator;
            DBOs.Notes.NoteTask dbo = Mapper.Map <DBOs.Notes.NoteTask>(model);

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

                if (currentModel != null)
                { // Update
                    conn.Execute("UPDATE \"note_task\" 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_task\" (\"id\", \"note_id\", \"task_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                                 "VALUES (@Id, @NoteId, @TaskId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                                 dbo);
                }
            }

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

            conn = DataHelper.OpenIfNeeded(conn);

            Common.Models.Notes.NoteTask currentModel = Get(model.Task.Id.Value, model.Note.Id.Value, conn, false);

            if (currentModel != null)
            { // Update
                conn.Execute("UPDATE \"note_task\" 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 \"note_task\" (\"id\", \"note_id\", \"task_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                                 "VALUES (@Id, @NoteId, @TaskId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                                 dbo) > 0)
                {
                    model.Id = conn.Query <DBOs.Notes.NoteTask>("SELECT currval(pg_get_serial_sequence('note_task', 'id')) AS \"id\"").Single().Id;
                }
            }

            DataHelper.Close(conn, closeConnection);

            return(model);
        }