コード例 #1
0
        public async Task <ActionResult <Response> > CreateAuthor(AuthorModel model)
        {
            var author = model.ToEntity();

            if (author.Invalid)
            {
                return(BadRequest(
                           ResponseHelper
                           .CreateResponse("Informações inválidas para criar um autor", author.Notifications)
                           ));
            }

            if (await _repository.AuthorExist(author))
            {
                return(UnprocessableEntity(
                           ResponseHelper
                           .CreateResponse("Email já cadastrado", model)));
            }

            await _repository.Add(author);

            return(CreatedAtAction(
                       nameof(GetAuthorById),
                       new { id = author.Id },
                       ResponseHelper.CreateResponse("Autor cadastrado com sucesso", AuthorModel.ToModel(author))));
        }
コード例 #2
0
        public AuthorViewModel Add(AuthorInputModel input)
        {
            var viewModel = _mapper.Map <AuthorViewModel>(input);
            var author    = _authorRepository.Add(_mapper.Map <Author>(viewModel));

            return(_mapper.Map <AuthorViewModel>(author));
        }
コード例 #3
0
        public IActionResult Post(Author authorDto)
        {
            Author author = authorDto;

            if (author is null)
            {
                return(BadRequest("Author object is null"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model is not valid"));
            }
            repository.Add(author);
            return(CreatedAtAction(nameof(Post), new { id = author.Id }, author));
            // return Ok(authorDto);
        }
コード例 #4
0
        public SaveAuthorResponse SaveAuthor(SaveAuthorRequest request)
        {
            var response = new SaveAuthorResponse()
            {
                Request       = request,
                ResponseToken = Guid.NewGuid()
            };

            try
            {
                if (request.Author?.Id == 0)
                {
                    response.Author    = request.Author;
                    response.Author.Id = _repository.Add(request.Author.MapToModel());
                    response.Success   = true;
                }
                else if (request.Author?.Id > 0)
                {
                    response.Author  = _repository.Save(request.Author.MapToModel()).MapToView();
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Success = false;
            }

            return(response);
        }
コード例 #5
0
        public Author CreateAuthor(Author author)
        {
            var returned = _authorRepository.Add(author);

            _authorRepository.SaveChanges();
            return(returned);
        }
コード例 #6
0
        public async Task <IActionResult> Post(UserAuthorDto userAuthorDto)
        {
            try
            {
                var user = mapper.Map <User>(userAuthorDto.UserDto);

                var result = await userManager.CreateAsync(user, userAuthorDto.UserDto.Password);

                if (result.Succeeded)
                {
                    var author = mapper.Map <Author>(userAuthorDto.AuthorDto);
                    author.User = user;

                    authorRepository.Add(author);

                    await authorRepository.SaveChangesAsync();

                    return(StatusCode(StatusCodes.Status201Created, "Usuário criado com sucesso!"));
                }
                return(StatusCode(StatusCodes.Status500InternalServerError, "Erro ao cadastrar usuário"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #7
0
 public RedirectToActionResult Add(string name, DateTime bDay, int bookId)
 {
     authorRepo.Add(new Author {
         Name = name, Birthday = bDay, BookID = bookId
     });
     return(RedirectToAction("Index", "Book"));
 }
コード例 #8
0
        public async Task Create(AuthorCreateModel authorCreateModel)
        {
            if (authorCreateModel == null ||
                authorCreateModel.FirstName.IsNullOrEmpty() ||
                authorCreateModel.SecondName.IsNullOrEmpty())
            {
                throw new CustomException("Некоректные данные");
            }
            var authors = await _authorRepository.GetAll();

            if (authors == null)
            {
                throw new ServerException("Сервер вернул null");
            }
            if (authors.Any(w =>
                            string.Equals(w.FirstName, authorCreateModel.FirstName) &&
                            string.Equals(w.SecondName, authorCreateModel.SecondName)))
            {
                throw new CustomException("Такой автор уже существует");
            }
            var result = await _authorRepository.Add(_mapper.Map <Author>(authorCreateModel));

            if (result == null)
            {
                throw new ServerException("Ошибка в БД");
            }
        }
コード例 #9
0
 public void AddAuthor(string authorName, User user)
 {
     authorRepository.Add(new Author()
     {
         Id = Guid.NewGuid(), User = user, Name = authorName
     });
 }
コード例 #10
0
        public void AdicionandoAuthor()
        {
            var shelf = new Shelf
            {
                Number = 5000
            };


            _books.Add(new Book()
            {
                Name = "Malditos Comunistas", Shelf = shelf
            });
            _books.Add(new Book()
            {
                Name = "Parasitas do Estado", Shelf = shelf
            });

            var author = new Author
            {
                Name  = "Allan Egidio",
                Books = _books,
            };

            var authors = _authorRepository.Get();

            _authorRepository.Add(author);
            _uow.Commit();
        }
コード例 #11
0
        public Author SaveAsync(Author author)
        {
            var inserted = _authorRepository.Add(author);

            _unitOfWork.Complete();

            return(inserted);
        }
コード例 #12
0
        protected override async Task Handle(CreateAuthorCommand request, CancellationToken cancellationToken)
        {
            var author = new Core.Models.Author
            {
                Name = request.Name,
            };

            await _authorRepository.Add(author, cancellationToken);
        }
コード例 #13
0
 public void Add(string nickname, string email)
 {
     authorRepository.Add(new Author()
     {
         Nickname = nickname,
         Email    = email,
         Votes    = 0,
     });
 }
コード例 #14
0
 public IActionResult Create(Author author)
 {
     if (ModelState.IsValid)
     {
         _authors.Add(author);
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
コード例 #15
0
        public IActionResult Post([FromBody] Author value)
        {
            if (value == null)
            {
                return(BadRequest());
            }
            var createdAuthor = _authorRepository.Add(value);

            return(CreatedAtRoute("GetAuthor", new { id = createdAuthor.AuthorId }, createdAuthor));
        }
コード例 #16
0
 public RedirectToActionResult Add(string name, DateTime bDay, int bookId)
 {
     if (ModelState.IsValid)
     {
         authorRepo.Add(new Author {
             Name = name, Birthday = bDay
         });
     }
     return(RedirectToAction("Index", "Book"));
 }
コード例 #17
0
ファイル: AuthorService.cs プロジェクト: lascau/Influencers
 public void AddAuthor(string nickname, string email, int?votes)
 {
     _authorRepository.Add(new Author()
     {
         //AuthorId = _authorRepository.NoAuthorsInTable() + 1,
         Nickname = nickname,
         Email    = email,
         Votes    = votes
     });
 }
コード例 #18
0
        public IActionResult Create([FromBody] Author item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _AuthorRepository.Add(item);

            return(CreatedAtRoute("GetTodo", new { id = item.ID }, item));
        }
コード例 #19
0
        public async Task <Author> Add(Author author)
        {
            if (_authorRepository.Search(p => p.Name == author.Name).Result.Any())
            {
                return(null);
            }

            await _authorRepository.Add(author);

            return(author);
        }
コード例 #20
0
        public Task <bool> Handle(AddNewAuthorCommand request, CancellationToken cancellationToken)
        {
            var author = new Author(request.Name);

            foreach (var book in request.Books)
            {
                author.AddBook(book.Name);
            }
            _authorRepository.Add(author);
            return(_authorRepository.UnitOfWork.SaveEntitiesAsync());
        }
コード例 #21
0
ファイル: AuthorService.cs プロジェクト: jvstek/AuthorRouting
        public Guid Create(CreateAuthorModel model)
        {
            var newAuthor = new Author
            {
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                DateOfBirth = model.DateOfBirth
            };

            repository.Add(newAuthor);
            return(newAuthor.AuthorId);
        }
コード例 #22
0
        public int AddAuthor(AddAuthorViewModel addAuthor)
        {
            Author author = new Author
            {
                FirstName = addAuthor.FirstName,
                LastName  = addAuthor.LastName
            };

            _authorRepository.Add(author);
            _authorRepository.SaveChange();
            return(author.Id);
        }
コード例 #23
0
        public IActionResult CreateAuthor(Author author)
        {
            if (ModelState.IsValid)
            {
                authorRepository.Add(author);
                return(RedirectToAction("DisplayAllAuthors"));
            }

            CreateAuthorViewModel viewModel = GetAuthorViewModel(new Author(), null);

            return(View("Views/Admin/Author/CreateAuthor.cshtml", viewModel));
        }
コード例 #24
0
        public async Task <AuthorResponse> AddAuthorAsync(AddAuthorRequest
                                                          request)
        {
            var item = new Domain.Entities.Author
            {
                AuthorName =
                    request.AuthorName
            };
            var result = _artistRepository.Add(item);
            await _artistRepository.UnitOfWork.SaveChangesAsync();

            return(_artistMapper.Map(result));
        }
        public Result Handle(CreateAuthorCommand command)
        {
            var validationResult = Validate(command, _createAuthorCommandValidator);

            if (validationResult.IsValid)
            {
                var author = Mapper <Domain.Entities.Author, CreateAuthorCommand> .CommandToEntity(command);

                _authorRepository.Add(author);
                _authorRepository.SaveChanges();
            }

            return(Return());
        }
コード例 #26
0
        public Author Add(Author author)
        {
            _logger.LogInfoCreateMethodStarted <Author>(AuthorRepositoryType, nameof(Add), new object[] { author });

            if (author is null)
            {
                _logger.LogWarningCreateMethodNullData <Author>(AuthorRepositoryType, nameof(Add));
            }

            var result = _authorRepository.Add(author);

            _logger.LogInfoCreateMethodEnded(AuthorRepositoryType, nameof(Add), result);
            return(result);
        }
コード例 #27
0
ファイル: AuthorService.cs プロジェクト: TPAKC/EducationApp
        public async Task <BaseModel> CreateAsync(string name)
        {
            var resultModel = new BaseModel();
            var author      = new Author();

            author.Name = name;
            var result = await _authorRepository.Add(author);

            if (result == 0)
            {
                resultModel.Errors.Add(FailedToCreateAuthor);
            }
            return(resultModel);
        }
コード例 #28
0
        public int Add(Author author)
        {
            if (!ValidadeNotExists(author.Name))
            {
                return(0);
            }
            var response = _authorRepository.Add(author);

            if (response != 0)
            {
                _logService.Log(author, "Add");
            }
            return(response);
        }
コード例 #29
0
 public ActionResult Create(Author entity)
 {
     if (ModelState.IsValid)
     {
         using (IUnitOfWork uow = uowFactory.Create()) {
             repository.Add(entity);
             uow.Save();
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(View());
     }
 }
コード例 #30
0
        public async Task <ActionResult> Add([FromBody] Author author)
        {
            var result = await _authorRepository.Add(author);

            if (author == null)
            {
                return(NotFound());
            }

            return(Ok(new
            {
                result.Id,
                result.Name
            }));
        }
コード例 #31
0
        private void AddAuthor(Comic comic, IAuthorRepository authorRepository, string authorStr)
        {
            if (string.IsNullOrEmpty(authorStr)) return;

            string[] authors = authorStr.Split(',');

            foreach (string author in authors)
            {
                string authorTrim = author.Trim();

                Author authorDb = authorRepository.Find(a => a.AuthorName.Equals(authorTrim)).FirstOrDefault();

                if (authorDb == null)
                {
                    authorDb = new Author
                    {
                        AuthorName = authorTrim,
                        Comics = new List<Comic>()
                    };

                    authorDb.Comics.Add(comic);
                    authorRepository.Add(authorDb);
                }
                else
                {
                    if (authorDb.Comics == null) authorDb.Comics = new List<Comic>();
                    if (authorDb.Comics.Any(c => c.ComicUrl.Equals(comic.ComicUrl))) continue;

                    authorDb.Comics.Add(comic);
                    authorRepository.Edit(authorDb);
                }

                if (comic.Authors == null) comic.Authors = new List<Author>();
                if (!comic.Authors.Any(a => a.AuthorName.Equals(authorTrim)))
                {
                    comic.Authors.Add(authorDb);
                }

                authorRepository.Save();
            }
        }