public IActionResult Create(CreateBookDto createBookDto) { try { if (ModelState.IsValid) { var response = _booksService.Create(createBookDto.ToModel()); if (response.IsSuccessfull) { return(Ok(response.Message)); } else { ModelState.AddModelError("", response.Message); //return BadRequest(ModelState); } } return(BadRequest(ModelState)); } catch (Exception) { return(StatusCode(500)); } }
public async Task <ActionResult> Create(Book book) { if (ModelState.IsValid) { await _service.Create(book); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <ActionResult> Create(CreateBook model) { if (ModelState.IsValid) { // model.CreatorUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var newItem = await _booksService.Create(model); return(RedirectToAction("Index", "Books")); } return(View()); }
public IActionResult Create(BookDto book) { if (ModelState.IsValid) { var status = _booksService.Create(book.ToDomainModel()); if (status) { return(Ok()); } else { ModelState.AddModelError("", "Book with same title already exists"); } } return(BadRequest(ModelState)); }
/// <inheritdoc /> public async Task ParsePiter() { var books = _piterParser.GetPiter(); #region Создание/Получение издательства Guid publishingGuid = Guid.Empty; CreatePublishingModel publishing = new CreatePublishingModel(); publishing.PublishingGuid = Guid.NewGuid(); publishing.Name = "Издательский дом 'Питер'"; publishing.City = "г. Санкт-Петербург"; publishing.Country = "Россия"; publishing.House = "дом № 29, литера А"; publishing.Postcode = 194044; publishing.State = "Ленинградская обл."; publishing.Street = "Большой Сампсониевский пр-кт"; var searchPublishing = await _publishingsService.Search(publishing.Name); if (searchPublishing.Any()) { var publishingModel = await _publishingsService.Read(searchPublishing.First().PublishingGuid); publishingGuid = publishingModel.PublishingGuid; } else { publishingGuid = await _publishingsService.Create(publishing); } #endregion foreach (var book in books) { try { CreateBookModel createBookModel = new CreateBookModel(); // Издательство и авторы createBookModel.CreationDateTimeOffset = DateTimeOffset.Now; createBookModel.PublishingGuid = publishingGuid; createBookModel.AuthorGuid = new List <Guid>(); #region Создание/Добавление автора foreach (var authorsName in book.AuthorsNames) { var fullname = authorsName.Split(' '); CreateAuthorModel author = new CreateAuthorModel(); author.AuthorGuid = Guid.NewGuid(); author.Surname = fullname[0]; author.Name = fullname[1]; if (fullname.Length == 3) { author.Patronymic = fullname[2]; } author.Note = "Автор книг: \"" + book.Title + "\""; var searchAuthor = await _authorsService.Search(author.Surname); if (searchAuthor.Any()) { foreach (var item in searchAuthor) { UpdateAuthorModel updateAuthorModel = new UpdateAuthorModel(); updateAuthorModel.AuthorGuid = item.AuthorGuid; updateAuthorModel.Name = item.Name; updateAuthorModel.Surname = item.Surname; updateAuthorModel.Patronymic = item.Patronymic; if (!item.Note.Contains(book.Title)) { updateAuthorModel.Note = item.Note + ", \"" + book.Title + "\""; } await _authorsService.Update(updateAuthorModel); createBookModel.AuthorGuid.Add(item.AuthorGuid); } } else { var guid = await _authorsService.Create(author); createBookModel.AuthorGuid.Add(guid); } } #endregion #region Создание/Добавление сферы применения // Сфера применения CreateTechnologyModel technology = new CreateTechnologyModel(); technology.TechnologyGuid = Guid.NewGuid(); technology.Name = book.TechnologiesName; technology.Description = "Серия книг: " + technology.Name; technology.Language = "-"; var searchTechnologies = await _technologiesService.Search(technology.Name); if (searchTechnologies.Any()) { var technologyModel = await _technologiesService.Read(searchTechnologies.First().TechnologyGuid); createBookModel.TechnologyGuid = technologyModel.TechnologyGuid; } else { createBookModel.TechnologyGuid = await _technologiesService.Create(technology); } #endregion createBookModel.BookGuid = Guid.NewGuid(); createBookModel.Title = book.Title; createBookModel.Annotation = book.Annotation; createBookModel.Cover = book.Cover; try { createBookModel.NumberOfPages = Convert.ToInt32(book.NumberOfPages); } catch (Exception) { createBookModel.NumberOfPages = 0; } createBookModel.Format = book.Format; createBookModel.Cost = "Электронная книга: " + book.CostDigital + ";\nБумажная книга: " + book.CostPaper; try { createBookModel.Year = Convert.ToInt32(book.Year); } catch (Exception) { createBookModel.Year = 2019; } createBookModel.BuyUri = book.BuyUri; createBookModel.ImageUri = book.ImageUri; var result = await _booksService.Create(createBookModel); } catch (Exception e) { Console.WriteLine(e); } } }
public async Task <IActionResult> CreateBook(CreateBookModel bookModel) { await _booksService.Create(bookModel); return(RedirectToAction(nameof(ReadAll))); }
public async Task <EntityDto> Post(BookDto bookDto) { var createBook = await _booksService.Create(bookDto); return(createBook); }