public bool Move( FavoritesLink msg, FavoritesFolder newParent) { if (FindByMessageId(newParent.Links, msg.MessageId) != null) { return(false); } var oldParent = (FavoritesFolder)msg.Parent; // здесь, т.к. в Links.Add() Parent будет переустановлен newParent.Links.Add(msg); using (var db = _provider.CreateDBContext()) db .FavoriteItems(fi => fi.ID == ((IFavoritesEntry)msg).Id) .Set(_ => _.FolderID, newParent.Id) .Update(); oldParent.Links.Remove(msg); newParent.SortLinks(Config.Instance.FavoritesMessagesSortCriteria); return(true); }
public void Delete(FavoritesLink link) { var parentFolder = (FavoritesFolder)link.Parent; using (var db = _provider.CreateDBContext()) db.FavoriteItems(fi => fi.ID == link.Id).Delete(); parentFolder.Links.Remove(link); SetFavoriteLinksSetDirty(); }
public void Update(FavoritesLink link) { using (var db = _provider.CreateDBContext()) db .FavoriteItems(fi => fi.ID == link.Id) .Set(_ => _.Comment, link.Comment) .Set(_ => _.Url, link.Url) .Update(); }
public void AddUrlLink(string url, string comment, FavoritesFolder folder) { var link = FavoritesLink.CreateInstance(_provider, -1, url, comment, folder); folder.Links.Add(link); InsertFavoritesLink(link); SetFavoriteLinksSetDirty(); }
public bool AddMessageLink(int messageId, string comment, FavoritesFolder folder) { if (FindByMessageId(folder.Links, messageId) != null) { return(false); } var link = FavoritesLink.CreateInstance(_provider, -1, messageId, comment, folder); folder.Links.Add(link); InsertFavoritesLink(link); SetFavoriteLinksSetDirty(); return(true); }
private void InsertFavoritesLink(FavoritesLink link) { using (var db = _provider.CreateDBContext()) using (var tx = db.BeginTransaction()) { db .IntoFavoriteItems() .Value(_ => _.MessageID, link.MessageId) .Value(_ => _.FolderID, link.Parent.Id) .Value(_ => _.Comment, link.Comment) .Value(_ => _.Url, link.Url) .Insert(); link.Id = db.FavoriteItems().Max(fi => fi.ID); tx.Commit(); } }
public bool Move( FavoritesLink msg, FavoritesFolder newParent) { if (FindByMessageId(newParent.Links, msg.MessageId) != null) return false; var oldParent = (FavoritesFolder)msg.Parent; // здесь, т.к. в Links.Add() Parent будет переустановлен newParent.Links.Add(msg); using (var db = _provider.CreateDBContext()) db .FavoriteItems(fi => fi.ID == ((IFavoritesEntry)msg).Id) .Set(_ => _.FolderID, newParent.Id) .Update(); oldParent.Links.Remove(msg); newParent.SortLinks(Config.Instance.FavoritesMessagesSortCriteria); return true; }