public async Task <IActionResult> Edit(BookFormBindingModel model)
        {
            if (model.File != null)
            {
                if (!(model.File.ContentType == WebConstants.JpgMimeType ||
                      model.File.ContentType == WebConstants.PngMimeType ||
                      model.File.ContentType == WebConstants.GifMimeType))
                {
                    TempData.AddErrorMessage(WebConstants.NotSupportedFile);
                    return(this.View(model));
                }

                var filePath = await this.booksService.GetPictureUrlByIdAsync(model.Id);

                model.PictureUrl = await model.File.SaveToFileSystem(this.RootPath, WebConstants.BooksFolder, filePath);
            }

            var book   = this.mapper.Map <BookFormModel>(model);
            var result = await this.booksService.EditAsync(book);

            if (!result)
            {
                TempData.AddErrorMessage(WebConstants.SaveBookError);
                return(this.View(model));
            }

            TempData.AddSuccessMessage(WebConstants.SaveBookSuccess);

            return(this.RedirectToAction(
                       nameof(TeachTheChild.Web.Controllers.ArticlesController.Details),
                       "Books",
                       new { area = "", id = model.Id, title = model.Title.ToFriendlyUrl() }));
        }
        public async Task <IActionResult> Add(BookFormBindingModel model)
        {
            model.UserId     = this.userManager.GetUserId(this.User);
            model.LanguageId = await this.usersService.GetUserLanguageIdAsync(model.UserId);

            if (model.LanguageId == 0)
            {
                TempData.AddErrorMessage(WebConstants.SaveDownloadsError);
                return(this.View(model));
            }

            if (model.File != null)
            {
                if (!(model.File.ContentType == WebConstants.JpgMimeType ||
                      model.File.ContentType == WebConstants.PngMimeType ||
                      model.File.ContentType == WebConstants.GifMimeType))
                {
                    TempData.AddErrorMessage(WebConstants.NotSupportedFile);
                    return(this.View(model));
                }

                model.PictureUrl = await model.File.SaveToFileSystem(this.RootPath, WebConstants.BooksFolder);
            }

            var book   = this.mapper.Map <BookFormModel>(model);
            var result = await this.booksService.AddAsync(book);

            if (result == 0)
            {
                TempData.AddErrorMessage(WebConstants.SaveBookError);
                return(this.View(model));
            }

            TempData.AddSuccessMessage(WebConstants.SaveBookSuccess);
            return(this.RedirectToAction(nameof(TeachTheChild.Web.Controllers.BooksController.Details),
                                         "Books",
                                         new { area = "", id = result, title = model.Title.ToFriendlyUrl() }));
        }