/// <summary> /// Get all available categories. /// </summary> /// <returns>A list of categories.</returns> public static Category[] Get() { Database db = new Database(); var categories = db.CategoryEntity.GetAll(); return Mapper.Map<Category[]>(categories); }
/// <summary> /// Delete a tag. /// </summary> /// <param name="id">The tag id.</param> /// <returns>True on success.</returns> public static bool Delete(int id) { Database db = new Database(); var tag = Get(id); return db.TagEntity.Delete(Mapper.Map<TagDTO>(tag)); }
/// <summary> /// Get a specified category by id. /// </summary> /// <param name="id">The category id.</param> /// <returns>The category.</returns> public static Category Get(int id) { Database db = new Database(); var category = db.CategoryEntity.Get(id); return Mapper.Map<Category>(category); }
/// <summary> /// Add a new book to database. /// </summary> /// <param name="model">The new book.</param> /// <returns>The new book.</returns> public static Book Add(Book model) { Database db = new Database(); var @in = Mapper.Map<BookDTO>(model); var result = db.BookEntity.Add(@in); var @out = Mapper.Map<Book>(result); return @out; }
/// <summary> /// Add a new tag to database. /// </summary> /// <param name="model">The new tag.</param> /// <returns>The new tag.</returns> public static Tag Add(Tag model) { Database db = new Database(); var @in = Mapper.Map<TagDTO>(model); var result = db.TagEntity.Add(@in); var @out = Mapper.Map<Tag>(result); return @out; }
/// <summary> /// Add a new category to database. /// </summary> /// <param name="model">The new category.</param> /// <returns>The new category</returns> public static Category Add(Category model) { Database db = new Database(); var @in = Mapper.Map<CategoryDTO>(model); var result = db.CategoryEntity.Add(@in); var @out = Mapper.Map<Category>(result); return @out; }
/// <summary> /// create a new tag or return existing tag. /// </summary> /// <param name="name">The tag name.</param> /// <returns>The tag.</returns> public static Tag Create(string name) { Database db = new Database(); //TODO modify filter and escape // look if the tag exists otherwise create them var tag = db.TagEntity.GetByName(name.Escape().Trim()); if (tag == null) { tag = db.TagEntity.Add(new TagDTO { Name = name.Escape().Trim() }); } return Mapper.Map<Tag>(tag); }
/// <summary> /// Get all tags related to this book. /// </summary> /// <returns></returns> public Tag[] GetTags() { Database db = new Database(); var tags = db.TagEntity.GetByBook(this.Id); var result = Mapper.Map<Tag[]>(tags); return result; }
/// <summary> /// Link a tag to the book. Return null if the link already exists. /// </summary> /// <param name="tag">The tag name.</param> /// <returns>The tag.</returns> public Tag AddTag(string name) { Database db = new Database(); // TODO validate the book before link tags // create the tag var tag = Tag.Create(name); // test if a link already exists var tags = GetTags(); if (tags.Where(s => s.Id == tag.Id).Count() == 0) { // link the tag to the book var link = db.Tag2BookEntity.Add(new Tag2BookDTO { BookId = this.Id, TagId = tag.Id }); return Mapper.Map<Tag>(tag); } return null; }
/// <summary> /// Get a suggestion list. The term can be book or story. /// </summary> /// <param name="term">The search term.</param> /// <returns>A list of suggestions.</returns> public static string[] SuggestionList(string term) { Database db = new Database(); string eterm = term.Escape().EscapeForSearch().Trim(); if (String.IsNullOrEmpty(eterm)) { return new string[] { }; } var suggestion = db.BookEntity.GetSuggestionList(eterm); return suggestion.ToArray(); }
/// <summary> /// Search for books or stories. /// </summary> /// <param name="term">The search term.</param> /// <returns>A list of books.</returns> public static Book[] Search(string term) { Database db = new Database(); //TODO modify filter and escape string eterm = term.Escape().EscapeForSearch().Trim(); if (String.IsNullOrEmpty(eterm)) { return new Book[] { }; } var books = db.BookEntity.GetByTerm(eterm); return Mapper.Map<Book[]>(books); }
/// <summary> /// Get a specified book by id. /// </summary> /// <param name="id">The book id.</param> /// <returns>The book.</returns> public static Book Get(int id) { Database db = new Database(); var book = db.BookEntity.Get(id); var _book = Mapper.Map<Book>(book); return _book; }
/// <summary> /// Get all books related to this tag. /// </summary> /// <returns></returns> public Book[] GetBooks() { Database db = new Database(); var books = db.BookEntity.GetByTag(this.Id); var result = Mapper.Map<Book[]>(books); return result; }
/// <summary> /// Get a specified tag by id. /// </summary> /// <param name="id">The tag id.</param> /// <returns>The tag.</returns> public static Tag Get(int id) { Database db = new Database(); var tag = db.TagEntity.Get(id); return Mapper.Map<Tag>(tag); }
/// <summary> /// Set image to book. /// </summary> /// <param name="filename"></param> /// <returns></returns> public Book SetImage(string filename) { Database db = new Database(); var book = Get(this.Id); ImageStore.Remove(book.Filename); book.Filename = filename; var _book = Mapper.Map<BookDTO>(book); return Mapper.Map<Book>(db.BookEntity.UpdateImage(_book)); }
/// <summary> /// Unlink a tag this book. /// </summary> /// <param name="id">The tag id.</param> /// <returns>True on success.</returns> public bool Unlink(int id) { Database db = new Database(); var _tag = Tag.Get(id); return db.Tag2BookEntity.Delete(new Tag2BookDTO { TagId = _tag.Id, BookId = this.Id }); }
/// <summary> /// Get all available tags. /// </summary> /// <returns>A list of tags</returns> public static Tag[] Get() { Database db = new Database(); var tags = db.TagEntity.GetAll(); return Mapper.Map<Tag[]>(tags); }
public static bool Delete(int id) { Database db = new Database(); var book = Get(id); if(ImageStore.Exists(book.Filename)) { ImageStore.Remove(book.Filename); } return db.BookEntity.Delete(new BookDTO { Id = id }); }
/// <summary> /// Get all available books from database. /// </summary> /// <returns>A list of books.</returns> public static Book[] Get() { Database db = new Database(); var books = db.BookEntity.GetAll(); return Mapper.Map<Book[]>(books); }