Пример #1
0
        public static Common.Models.Events.EventTag Create(Common.Models.Events.EventTag model,
                                                           Common.Models.Account.Users creator)
        {
            if (!model.Id.HasValue)
            {
                model.Id = Guid.NewGuid();
            }
            model.CreatedBy = model.ModifiedBy = creator;
            model.Created   = model.Modified = DateTime.UtcNow;

            Common.Models.Tagging.TagCategory existingTagCat = Tagging.TagCategory.Get(model.TagCategory.Name);

            if (existingTagCat == null)
            {
                existingTagCat = Tagging.TagCategory.Create(model.TagCategory, creator);
            }

            model.TagCategory = existingTagCat;
            DBOs.Events.EventTag dbo = Mapper.Map <DBOs.Events.EventTag>(model);

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("INSERT INTO \"event_tag\" (\"id\", \"event_id\", \"tag_category_id\", \"tag\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                             "VALUES (@Id, @EventId, @TagCategoryId, @Tag, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                             dbo);
            }

            return(model);
        }
 public static Common.Models.Tagging.TagCategory Enable(
     Transaction t,
     Common.Models.Tagging.TagCategory model,
     Common.Models.Account.Users enabler)
 {
     return(Enable(model, enabler, t.Connection, false));
 }
 public static Common.Models.Tagging.TagCategory Create(
     Transaction t,
     Common.Models.Tagging.TagCategory model,
     Common.Models.Account.Users creator)
 {
     return(Create(model, creator, t.Connection, false));
 }
Пример #4
0
        public static Common.Models.Events.EventTag Create(Common.Models.Events.EventTag 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;

            Common.Models.Tagging.TagCategory existingTagCat =
                Tagging.TagCategory.Get(model.TagCategory.Name, conn, false);

            if (existingTagCat == null)
            {
                existingTagCat = Tagging.TagCategory.Create(model.TagCategory, creator, conn, false);
            }

            model.TagCategory = existingTagCat;
            DBOs.Events.EventTag dbo = Mapper.Map <DBOs.Events.EventTag>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            conn.Execute("INSERT INTO \"event_tag\" (\"id\", \"event_id\", \"tag_category_id\", \"tag\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                         "VALUES (@Id, @EventId, @TagCategoryId, @Tag, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                         dbo);

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
Пример #5
0
        public static Common.Models.Tagging.TagCategory Disable(Common.Models.Tagging.TagCategory model,
                                                                Common.Models.Account.Users disabler)
        {
            model.DisabledBy = disabler;
            model.Disabled   = DateTime.UtcNow;

            DataHelper.Disable <Common.Models.Tagging.TagCategory,
                                DBOs.Tagging.TagCategory>("tag_category", disabler.PId.Value, model.Id);

            return(model);
        }
        public static Common.Models.Tagging.TagCategory Disable(
            Common.Models.Tagging.TagCategory model,
            Common.Models.Account.Users disabler,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            model.DisabledBy = disabler;
            model.Disabled   = DateTime.UtcNow;

            DataHelper.Disable <Common.Models.Tagging.TagCategory,
                                DBOs.Tagging.TagCategory>("tag_category", disabler.PId.Value, model.Id, conn, closeConnection);

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

            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("INSERT INTO \"tag_category\" (\"name\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                             "VALUES (@Name, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                             dbo);
                model.Id = conn.Query <DBOs.Tagging.TagCategory>("SELECT currval(pg_get_serial_sequence('tag_category', 'id')) AS \"id\"").Single().Id;
            }

            return(model);
        }
Пример #8
0
        private static Common.Models.Tagging.TagCategory AddOrChangeTagCategory(
            Common.Models.Matters.MatterTag tag,
            Common.Models.Account.Users modifier,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            Common.Models.Tagging.TagCategory newTagCat = null;

            // Check for existing name
            if (tag.TagCategory != null && !string.IsNullOrEmpty(tag.TagCategory.Name))
            {
                newTagCat = Tagging.TagCategory.Get(tag.TagCategory.Name, conn, false);
            }

            // Either need to use existing or create a new tag category
            if (newTagCat != null)
            {
                // Can use existing
                tag.TagCategory = newTagCat;

                // If new tagcat was disabled, it needs enabled
                if (newTagCat.Disabled.HasValue)
                {
                    tag.TagCategory = Tagging.TagCategory.Enable(tag.TagCategory, modifier, conn, false);
                }
            }
            else
            {
                // Add one
                tag.TagCategory = Tagging.TagCategory.Create(tag.TagCategory, modifier, conn, false);
            }

            conn = DataHelper.OpenIfNeeded(conn);

            // Update MatterTag's TagCategoryId
            conn.Execute("UPDATE \"matter_tag\" SET \"tag_category_id\"=@TagCategoryId WHERE \"id\"=@Id",
                         new { Id = tag.Id.Value, TagCategoryId = tag.TagCategory.Id });

            DataHelper.Close(conn, closeConnection);

            return(tag.TagCategory);
        }
Пример #9
0
        private static Common.Models.Tagging.TagCategory AddOrChangeTagCategory(
            Common.Models.Events.EventTag tag,
            Common.Models.Account.Users modifier)
        {
            Common.Models.Tagging.TagCategory newTagCat = null;

            // Check for existing name
            if (tag.TagCategory != null && !string.IsNullOrEmpty(tag.TagCategory.Name))
            {
                newTagCat = Tagging.TagCategory.Get(tag.TagCategory.Name);
            }

            // Either need to use existing or create a new tag category
            if (newTagCat != null)
            {
                // Can use existing
                tag.TagCategory = newTagCat;

                // If new tagcat was disabled, it needs enabled
                if (newTagCat.Disabled.HasValue)
                {
                    tag.TagCategory = Tagging.TagCategory.Enable(tag.TagCategory, modifier);
                }
            }
            else
            {
                // Add one
                tag.TagCategory = Tagging.TagCategory.Create(tag.TagCategory, modifier);
            }

            // Update MatterTag's TagCategoryId
            using (IDbConnection conn = Database.Instance.GetConnection())
            {
                conn.Execute("UPDATE \"event_tag\" SET \"tag_category_id\"=@TagCategoryId WHERE \"id\"=@Id",
                             new { Id = tag.Id.Value, TagCategoryId = tag.TagCategory.Id });
            }

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

            conn = DataHelper.OpenIfNeeded(conn);

            if (conn.Execute("INSERT INTO \"tag_category\" (\"name\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                             "VALUES (@Name, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                             dbo) > 0)
            {
                model.Id = conn.Query <DBOs.Tagging.TagCategory>("SELECT currval(pg_get_serial_sequence('tag_category', 'id')) AS \"id\"").Single().Id;
            }

            DataHelper.Close(conn, closeConnection);

            return(model);
        }