public void Update(Guid id, UpdateAuthorModel updateModel)
        {
            var entity = repository.Get(id);

            entity.LastName    = updateModel.LastName;
            entity.FirstName   = updateModel.FirstName;
            entity.DateOfBirth = updateModel.DateOfBirth;
        }
Exemple #2
0
        /// <inheritdoc />
        public async Task Update(UpdateAuthorModel model)
        {
            var author = await _context.Authors.FindAsync(model.AuthorGuid);

            author = _mapper.Map <Author>(model);

            await _context.SaveChangesAsync();
        }
Exemple #3
0
 public void Update(Guid id, UpdateAuthorModel author)
 {
     if (!_authorDictionary.TryGetValue(id, out var model))
     {
         return;
     }
     model.FirstName   = author.FirstName;
     model.LastName    = author.LastName;
     model.DateOfBirth = author.DateOfBirth;
 }
Exemple #4
0
        /// <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);
                }
            }
        }
Exemple #5
0
 public IActionResult Update([FromBody] UpdateAuthorModel model, Guid id)
 {
     AuthorService.Update(id, model);
     return(Ok());
 }