public IActionResult DeleteBook(string id, ManagePanelViewModel model)
        {
            if (!(model.Id == null || model.Id.Equals(string.Empty)))
            {
                if (!_manage.DeleteById((int)model.Id))
                {
                    model.OperationErrorName = model.Errors.ElementAt((int)OperationError.remove);
                }
            }
            else
            {
                model.OperationErrorName = model.Errors.ElementAt((int)OperationError.remove);
            }
            model.BookRemoved = true;
            //int convertedId;
            //if(Int32.TryParse(id, out convertedId))
            //_manage.DeleteById(convertedId);

            return(RedirectToAction("ManagePanel", model));
        }
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> ManagePanel(ManagePanelViewModel model)
        {
            model.BookAdded          = false;
            model.BookModified       = false;
            model.BookRemoved        = false;
            model.BookSearched       = false;
            model.OperationErrorName = string.Empty;
            if (!model.PagesRangeSelected)
            {
                model.PagesMin = null;
                model.PagesMax = null;
            }

            switch (model.OperationType)
            {
            case "add":
                if (!await _manage.Add(model.Title, model.ISBN, model.Pages,
                                       model.Author, model.Publisher, model.Category,
                                       model.Book, model.BookCovering, model.CopiesCount))
                {
                    model.OperationErrorName = model.Errors.ElementAt((int)OperationError.add);
                }
                model.BookAdded = true;
                break;

            case "update":
                if (!_manage.UpdateById(model.Id, model.Title, model.ISBN,
                                        model.Author, model.Pages, model.Publisher, model.Category))
                {
                    model.OperationErrorName = model.Errors.ElementAt((int)OperationError.modify);
                }
                model.BookModified = true;
                break;

            case "delete":
                if (!(model.Id == null || model.Id.Equals(string.Empty)))
                {
                    if (!_manage.DeleteById((int)model.Id))
                    {
                        model.OperationErrorName = model.Errors.ElementAt((int)OperationError.remove);
                    }
                }
                else
                {
                    model.OperationErrorName = model.Errors.ElementAt((int)OperationError.remove);
                }
                model.BookRemoved = true;
                break;

            case "select":
                if (model.Id == null || model.Id.Equals(string.Empty))
                {
                    model.BookSearched = true;

                    if (model.Category == null)
                    {
                        var firstCategory = _manage.GetAllCategories().FirstOrDefault();
                        if (firstCategory != default(Category))
                        {
                            model.Category = firstCategory.Name;
                        }
                    }

                    model.Books = _manage.GetBooks(model.Title, model.ISBN, model.Author,
                                                   model.PagesMin, model.PagesMax, model.Publisher, model.Category);

                    if (model.Availability)
                    {
                        model.Books = model.Books.Where(b => b.CopiesCount > 0);
                    }

                    var elementsCount = 0;

                    if (!(model.Books == null))
                    {
                        elementsCount = model.Books.Count();
                    }

                    var allPagesCount = elementsCount / model.ElementsOnPage;

                    var elementsToTake = model.ElementsOnPage;

                    if (elementsCount % model.ElementsOnPage != 0)
                    {
                        allPagesCount++;
                    }
                    if (model.Page < 1)
                    {
                        model.Page = 1;
                    }
                    if (model.Page > allPagesCount)
                    {
                        model.Page = model.AllPagesCount;
                    }
                    model.AllPagesCount = allPagesCount;
                    if (model.Page.Equals(model.AllPagesCount))
                    {
                        elementsToTake = elementsCount - ((model.AllPagesCount - 1) * model.ElementsOnPage);
                    }
                    if (elementsCount > 0)
                    {
                        model.Books       = model.Books.Skip((model.Page - 1) * model.ElementsOnPage).Take(elementsToTake);
                        model.AnyElements = true;
                    }
                    else
                    {
                        model.AnyElements = false;
                    }
                    if (elementsCount <= model.ElementsOnPage)
                    {
                        model.MoreThanOnePage = false;
                    }
                }
                else
                {
                    model.BookSearched = true;
                    var book = _manage.GetById((int)model.Id);
                    if (book != null)
                    {
                        model.Books = new List <Book>
                        {
                            book
                        };
                        model.AnyElements = true;
                    }
                }
                break;

            default:
                break;
            }
            model.Operations = operations;
            model.Categories = _manage.GetAllCategories();
            return(View(model));
        }