示例#1
0
        public SaveEBookResult SaveAndIndex(EBookCreateViewModel viewModel, string filePath, UserSessionObject user)
        {
            var           result            = new SaveEBookResult();
            BookViewModel completeViewModel = new BookViewModel(viewModel, user);

            SaveBookResult saveBook = BookService.Save(completeViewModel, user);

            if (saveBook.Success)
            {
                completeViewModel.Id = saveBook.Id;

                if (IndexEBook(completeViewModel, filePath))
                {
                    result = new SaveEBookResult(saveBook.Id, saveBook.Name);
                }
                else
                {
                    result.Success = false;
                    result.Message = "Error while indexing e-book.";

                    BookService.Delete(saveBook.Id, user); // rollback transaction
                }
            }
            else
            {
                result.Success = false;
                result.Message = saveBook.Message;
            }

            return(result);
        }
示例#2
0
        public ActionResult Create(EBookCreateViewModel viewModel)
        {
            var relativePath = "~/UploadedFiles/" + viewModel.Filename;
            var absolutePath = HttpContext.Server.MapPath(relativePath);

            SaveEBookResult   result = null;
            UserSessionObject user   = Session.GetUser();

            if (System.IO.File.Exists(absolutePath))
            {
                result = EBookService.SaveAndIndex(viewModel, absolutePath, user);
            }
            else
            {
                result = new SaveEBookResult()
                {
                    Success = false,
                    Message = "There is no file with given name. Please repeat upload!"
                };
            }

            return(Json(result));
        }