public static Common.Models.Assets.Version Create(
     Transaction t,
     Common.Models.Assets.Version model,
     Common.Models.Account.Users creator)
 {
     return(Create(model, creator, t.Connection, false));
 }
        public static Common.Models.Assets.Version Create(
            Common.Models.Assets.Version model,
            Common.Models.Account.Users creator,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            if (!model.Id.HasValue)
            {
                model.Id = Guid.NewGuid();
            }
            model.CreatedBy = model.ModifiedBy = creator;
            model.Created   = model.Modified = DateTime.UtcNow;
            DBOs.Assets.Version dbo = Mapper.Map <DBOs.Assets.Version>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            conn.Execute("INSERT INTO \"version\" (\"id\", \"sequence_number\", " +
                         "\"change_details\", \"asset_id\", " +
                         "\"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                         "VALUES (@Id, @SequenceNumber, @ChangeDetails, @AssetId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                         dbo);

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
 public static Common.Models.Assets.Version Edit(
     Transaction t,
     Common.Models.Assets.Version model,
     Common.Models.Account.Users modifier)
 {
     return(Edit(model, modifier, t.Connection, false));
 }
        public static Common.Models.Assets.Version Edit(
            Common.Models.Assets.Version model,
            Common.Models.Account.Users modifier,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            model.ModifiedBy = modifier;
            model.Modified   = DateTime.UtcNow;
            DBOs.Assets.Version dbo = Mapper.Map <DBOs.Assets.Version>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            conn.Execute("UPDATE \"version\" SET " +
                         "\"change_details\"=@ChangeDetails, " +
                         "\"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " +
                         "WHERE \"id\"=@Id", dbo);

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
        public static int GetNextVersionSequenceNumber(
            Guid assetId,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            conn = DataHelper.OpenIfNeeded(conn);

            Common.Models.Assets.Version currentVersion =
                DataHelper.Get <Common.Models.Assets.Version, DBOs.Assets.Version>(
                    "SELECT * FROM \"version\" WHERE \"asset_id\"=@AssetId AND " +
                    "\"utc_disabled\" is null ORDER BY \"sequence_number\" DESC LIMIT 1",
                    new { AssetId = assetId }, conn, closeConnection);

            if (currentVersion == null)
            {
                return(1);
            }
            else
            {
                return(currentVersion.SequenceNumber.Value + 1);
            }
        }