public IActionResult Create(CreateAuthorModel model)
        {
            if (!this.IfImgIsValid(model.Image))
            {
                return(View(model));
            }

            var fileName = model.Image.FileName;

            var extention = this.imgService.ReturnExtension(fileName);

            var currentNumberOnFolder = this.bookService.CountOfAllBooks() % GlobalConstants.NumberOnFolder;

            var currentFoledName = GlobalConstants.FolderNameImg + currentNumberOnFolder;

            var path = this.imgService.ReturnPath(environment, currentFoledName);

            var imgUrl = this.imgService.ReturnUrl(environment, currentFoledName, extention);

            if (!this.authorService.Create(model.Name, model.Details, imgUrl))
            {
                ModelState.AddModelError(string.Empty, CreateErrorMessage);
                return(View());
            }

            this.imgService.CreateImg(model.Image, path, imgUrl);

            return(Redirect(GlobalConstants.IndexPath));
        }
示例#2
0
        /// <inheritdoc />
        public async Task <Guid> Create(CreateAuthorModel model)
        {
            var author = _mapper.Map <Author>(model);

            _context.Authors.Add(author);
            await _context.SaveChangesAsync();

            return(author.AuthorGuid);
        }
示例#3
0
        public async Task <IActionResult> Create(CreateAuthorModel author)
        {
            Author model    = _mapper.Map <CreateAuthorModel, Author>(author);
            Author dbObject = await _authorService.Create(model);

            if (dbObject == null)
            {
                return(BadRequest());
            }
            return(Created("Created", _mapper.Map <Author, SuccessAuthorModel>(dbObject)));
        }
示例#4
0
        public Guid Create(CreateAuthorModel model)
        {
            var newAuthor = new Author
            {
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                DateOfBirth = model.DateOfBirth
            };

            repository.Add(newAuthor);
            return(newAuthor.AuthorId);
        }
示例#5
0
        public async Task <IActionResult> CreateAuthor(CreateAuthorModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            dispatcher.Dispatch(new CreateAuthorCommand {
                AuthorName = "Some author"
            });
            bool succeeded = await createAuthor.ExecuteAsync(model);

            if (!succeeded)
            {
                return(BadRequest("Could not create author"));
            }

            return(Ok(new { Status = "Created" }));
        }
示例#6
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);
                }
            }
        }
 public async Task CreateAuthor([FromForm] CreateAuthorModel author)
 {
     author.Name = author.AuthorName;
     await _authorsService.Create(author);
 }
示例#8
0
        public IActionResult Create([FromBody] CreateAuthorModel model)
        {
            Guid id = AuthorService.Create(model);

            return(CreatedAtRoute("GetAuthor", new { Id = id }, model));
        }