public static Common.Models.Tasks.TaskTag Create(Common.Models.Tasks.TaskTag 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.Tasks.TaskTag dbo = Mapper.Map <DBOs.Tasks.TaskTag>(model); using (IDbConnection conn = Database.Instance.GetConnection()) { conn.Execute("INSERT INTO \"task_tag\" (\"id\", \"task_id\", \"tag_category_id\", \"tag\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @TaskId, @TagCategoryId, @Tag, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo); } return(model); }
public static Common.Models.Tasks.TaskTag Create( Common.Models.Tasks.TaskTag 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.Tasks.TaskTag dbo = Mapper.Map <DBOs.Tasks.TaskTag>(model); conn = DataHelper.OpenIfNeeded(conn); conn.Execute("INSERT INTO \"task_tag\" (\"id\", \"task_id\", \"tag_category_id\", \"tag\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @TaskId, @TagCategoryId, @Tag, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo); DataHelper.Close(conn, closeConnection); return(model); }
public static List <Common.Models.Tasks.TaskTag> Search( string text, IDbConnection conn = null, bool closeConnection = true) { List <Common.Models.Tasks.TaskTag> list = new List <Common.Models.Tasks.TaskTag>(); List <DBOs.Tasks.TaskTag> dbo = null; conn = DataHelper.OpenIfNeeded(conn); dbo = conn.Query <DBOs.Tasks.TaskTag>( "SELECT * FROM \"task_tag\" WHERE LOWER(\"tag\") LIKE '%' || @Query || '%'", new { Query = text }).ToList(); dbo.ForEach(x => { Common.Models.Tasks.TaskTag tt = Mapper.Map <Common.Models.Tasks.TaskTag>(x); tt.TagCategory = Tagging.TagCategory.Get(tt.TagCategory.Id, conn, false); tt.Task = Task.Get(tt.Task.Id.Value, conn, false); list.Add(tt); }); DataHelper.Close(conn, closeConnection); return(list); }
public static Common.Models.Tasks.TaskTag Enable( Transaction t, Common.Models.Tasks.TaskTag model, Common.Models.Account.Users enabler) { return(Enable(model, enabler, t.Connection, false)); }
private static Common.Models.Tagging.TagCategory AddOrChangeTagCategory( Transaction t, Common.Models.Tasks.TaskTag tag, Common.Models.Account.Users modifier) { return(AddOrChangeTagCategory(tag, modifier, t.Connection, false)); }
public static Common.Models.Tasks.TaskTag Create( Transaction t, Common.Models.Tasks.TaskTag model, Common.Models.Account.Users creator) { return(Create(model, creator, t.Connection, false)); }
private static Common.Models.Tagging.TagCategory UpdateTagCategory( Transaction t, Common.Models.Tasks.TaskTag model, Common.Models.Account.Users modifier) { return(UpdateTagCategory(model, modifier, t.Connection, false)); }
public static Common.Models.Tasks.TaskTag Edit( Transaction t, Common.Models.Tasks.TaskTag model, Common.Models.Account.Users modifier) { return(Edit(model, modifier, t.Connection, false)); }
public static Common.Models.Tasks.TaskTag Disable(Common.Models.Tasks.TaskTag model, Common.Models.Account.Users disabler) { model.DisabledBy = disabler; model.Disabled = DateTime.UtcNow; DataHelper.Disable <Common.Models.Matters.MatterContact, DBOs.Matters.MatterContact>("task_tag", disabler.PId.Value, model.Id); return(model); }
public static Common.Models.Tasks.TaskTag Disable( Common.Models.Tasks.TaskTag model, Common.Models.Account.Users disabler, IDbConnection conn = null, bool closeConnection = true) { model.DisabledBy = disabler; model.Disabled = DateTime.UtcNow; DataHelper.Disable <Common.Models.Matters.MatterContact, DBOs.Matters.MatterContact>("task_tag", disabler.PId.Value, model.Id, conn, closeConnection); return(model); }
public static Common.Models.Tasks.TaskTag Edit(Common.Models.Tasks.TaskTag model, Common.Models.Account.Users modifier) { model.ModifiedBy = modifier; model.Modified = DateTime.UtcNow; DBOs.Tasks.TaskTag dbo = Mapper.Map <DBOs.Tasks.TaskTag>(model); using (IDbConnection conn = Database.Instance.GetConnection()) { conn.Execute("UPDATE \"task_tag\" SET " + "\"task_id\"=@TaskId, \"tag\"=@Tag, \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " + "WHERE \"id\"=@Id", dbo); } model.TagCategory = UpdateTagCategory(model, modifier); return(model); }
private static Common.Models.Tagging.TagCategory UpdateTagCategory( Common.Models.Tasks.TaskTag model, Common.Models.Account.Users modifier, IDbConnection conn = null, bool closeConnection = true) { Common.Models.Tasks.TaskTag currentTag = Get(model.Id.Value, conn, false); if (currentTag.TagCategory != null) { if (model.TagCategory != null && !string.IsNullOrEmpty(model.TagCategory.Name)) { // If current has tag & new has tag // Are they the same - ignore if so if (currentTag.TagCategory.Name != model.TagCategory.Name) { // Update - change tagcat model.TagCategory = AddOrChangeTagCategory(model, modifier, conn, false); } } else { // If current has tag & new !has tag // Update - drop tagcat currentTag.TagCategory = null; conn.Execute("UPDATE \"task_tag\" SET \"tag_category_id\"=null WHERE \"id\"=@Id", new { Id = model.Id.Value }); } } else { if (model.TagCategory != null && !string.IsNullOrEmpty(model.TagCategory.Name)) { // If current !has tag & new has tag // Update - add tagcat model.TagCategory = AddOrChangeTagCategory(model, modifier, conn, false); } // If current !has tag & new !has tag - do nothing } DataHelper.Close(conn, closeConnection); return(model.TagCategory); }
public static Common.Models.Tasks.TaskTag Get(Guid id) { Common.Models.Tasks.TaskTag model = DataHelper.Get <Common.Models.Tasks.TaskTag, DBOs.Tasks.TaskTag>( "SELECT * FROM \"task_tag\" WHERE \"id\"=@id AND \"utc_disabled\" is null", new { id = id }); if (model == null) { return(null); } if (model.TagCategory != null) { model.TagCategory = Tagging.TagCategory.Get(model.TagCategory.Id); } return(model); }
private static Common.Models.Tagging.TagCategory AddOrChangeTagCategory( Common.Models.Tasks.TaskTag 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); } // Update MatterTag's TagCategoryId conn.Execute("UPDATE \"task_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); }
public static List <Common.Models.Tasks.TaskTag> Search(string text) { List <Common.Models.Tasks.TaskTag> list = new List <Common.Models.Tasks.TaskTag>(); List <DBOs.Tasks.TaskTag> dbo = null; using (IDbConnection conn = Database.Instance.GetConnection()) { dbo = conn.Query <DBOs.Tasks.TaskTag>( "SELECT * FROM \"task_tag\" WHERE LOWER(\"tag\") LIKE '%' || @Query || '%'", new { Query = text }).ToList(); } dbo.ForEach(x => { Common.Models.Tasks.TaskTag tt = Mapper.Map <Common.Models.Tasks.TaskTag>(x); tt.TagCategory = Tagging.TagCategory.Get(tt.TagCategory.Id); tt.Task = Task.Get(tt.Task.Id.Value); list.Add(tt); }); return(list); }
public static Common.Models.Tasks.TaskTag Edit( Common.Models.Tasks.TaskTag model, Common.Models.Account.Users modifier, IDbConnection conn = null, bool closeConnection = true) { model.ModifiedBy = modifier; model.Modified = DateTime.UtcNow; DBOs.Tasks.TaskTag dbo = Mapper.Map <DBOs.Tasks.TaskTag>(model); conn = DataHelper.OpenIfNeeded(conn); conn.Execute("UPDATE \"task_tag\" SET " + "\"task_id\"=@TaskId, \"tag\"=@Tag, \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " + "WHERE \"id\"=@Id", dbo); model.TagCategory = UpdateTagCategory(model, modifier, conn, false); DataHelper.Close(conn, closeConnection); return(model); }
public static Common.Models.Tasks.TaskTag Get( Guid id, IDbConnection conn = null, bool closeConnection = true) { Common.Models.Tasks.TaskTag model = DataHelper.Get <Common.Models.Tasks.TaskTag, DBOs.Tasks.TaskTag>( "SELECT * FROM \"task_tag\" WHERE \"id\"=@id AND \"utc_disabled\" is null", new { id = id }, conn, false); if (model == null) { return(null); } if (model.TagCategory != null) { model.TagCategory = Tagging.TagCategory.Get(model.TagCategory.Id, conn, false); } DataHelper.Close(conn, closeConnection); return(model); }