/// <summary>
 /// Creates a book with specified userName as owner
 /// </summary>
 /// <param name="userName"></param>
 /// <param name="cbModel"></param>
 public void CreateBook(string userName, CreateBookModel cbModel)
 {
     var b = _db.Books.FirstOrDefault(bo => bo.Name == cbModel.Name);
     if (b != null)
     {
         b.Description = Utils.GetTaggedText(HttpUtility.UrlDecode(cbModel.Description));
         _db.SaveChanges();
         LuceneSearch.ClearLuceneIndexRecord(b.Id);
         LuceneSearch.Optimize();
         LuceneSearch.AddUpdateLuceneIndex(b);
         return;
     }
     var usr = FindUser(userName);
     var tags = Utils.GetTags(cbModel.Description);
     ICollection<Tag> resultTags = new Collection<Tag>();
     foreach (var tg in tags)
     {
         var tag = _db.Tags.FirstOrDefault(t => t.Value == tg.Value);
         if (tag != null) _db.Tags.FirstOrDefault(t => t.Value == tg.Value).Count++;
         else resultTags.Add(new Tag { Value = tg.Value, Count = 1 });
     }
     var book = new Book
     {
         Name = cbModel.Name,
         Date = DateTime.Now,
         Chapters = null,
         Dislikes = 0,
         Likes = 0,
         Tags = resultTags,
         Description = Utils.GetTaggedText(HttpUtility.UrlDecode(cbModel.Description)),
         User = usr
     };
     _db.Books.Add(book);
     _db.SaveChanges();
     var bk = FindBook(book.Name);
     LuceneSearch.AddUpdateLuceneIndex(bk);
     LuceneSearch.Optimize();
 }
 public ActionResult CreateBook(CreateBookModel model)
 {
     _repository.CreateBook(User.Identity.Name, model);
     return RedirectToAction("Show","Book",new {bookId = _repository.FindBook(model.Name).Id});
 }