示例#1
0
        public async Task <IActionResult> Create(string Name, string Author)
        {
            var book = new Creat_Book()
            {
                Author = Author, Name = Name, Type = BookTypeEnum.NOVEL
            };
            var result = await _booksService.CreateAsync(book);

            if (result.IsSucceed)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
示例#2
0
        public async Task <ServiceResult> CreateAsync(Creat_Book book)
        {
            try
            {
                var _book = _bookFactory.Create(book.Type).Create(book.Name, book.Author);
                var query = await _db.Books.FirstOrDefaultAsync(x => x.Name == _book.Name && x.Author == _book.Author);

                if (query != null)
                {
                    return(ServiceResult.Error("数据已经存在"));
                }
                await _db.Books.AddAsync(_book);

                await _db.SaveChangesAsync();

                return(ServiceResult.Success());
            }
            catch (Exception ex)
            {
                return(ServiceResult.Error(ex));
            }
        }