public async Task <PartialViewResult> TwoParams(string author, string technology) { var result = await _searchService.SearchOnTwoParameters( Guid.Parse(author), Guid.Parse(technology)); var authorModel = await _authorsService.Read(Guid.Parse(author)); var technologiesModel = await _technologiesService.Read(Guid.Parse(technology)); ViewBag.authorName = $"{authorModel.Surname} {authorModel.Name} {authorModel.Patronymic}"; ViewBag.authorInfo = $"{authorModel.Note}"; ViewBag.technology = $"{technologiesModel.Name}"; return(PartialView(result)); }
/// <inheritdoc /> public async Task <BookModel> Read(Guid bookGuid) { var book = await _context.Books.FindAsync(bookGuid); var bookModel = _mapper.Map <BookModel>(book); bookModel.AuthorModel = new List <AuthorModel>(); foreach (var guid in book.AuthorGuid) { var author = await _authorsService.Read(guid); bookModel.AuthorModel.Add(author); } bookModel.PublishingModel = await _publishingsService.Read(book.PublishingGuid); bookModel.TechnologyModel = await _technologiesService.Read(book.TechnologyGuid); return(bookModel); }
/// <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); } } }