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)))); }
public AuthorViewModel Add(AuthorInputModel input) { var viewModel = _mapper.Map <AuthorViewModel>(input); var author = _authorRepository.Add(_mapper.Map <Author>(viewModel)); return(_mapper.Map <AuthorViewModel>(author)); }
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); }
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); }
public Author CreateAuthor(Author author) { var returned = _authorRepository.Add(author); _authorRepository.SaveChanges(); return(returned); }
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)); } }
public RedirectToActionResult Add(string name, DateTime bDay, int bookId) { authorRepo.Add(new Author { Name = name, Birthday = bDay, BookID = bookId }); return(RedirectToAction("Index", "Book")); }
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("Ошибка в БД"); } }
public void AddAuthor(string authorName, User user) { authorRepository.Add(new Author() { Id = Guid.NewGuid(), User = user, Name = authorName }); }
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(); }
public Author SaveAsync(Author author) { var inserted = _authorRepository.Add(author); _unitOfWork.Complete(); return(inserted); }
protected override async Task Handle(CreateAuthorCommand request, CancellationToken cancellationToken) { var author = new Core.Models.Author { Name = request.Name, }; await _authorRepository.Add(author, cancellationToken); }
public void Add(string nickname, string email) { authorRepository.Add(new Author() { Nickname = nickname, Email = email, Votes = 0, }); }
public IActionResult Create(Author author) { if (ModelState.IsValid) { _authors.Add(author); return(RedirectToAction("Index")); } return(View(author)); }
public IActionResult Post([FromBody] Author value) { if (value == null) { return(BadRequest()); } var createdAuthor = _authorRepository.Add(value); return(CreatedAtRoute("GetAuthor", new { id = createdAuthor.AuthorId }, createdAuthor)); }
public RedirectToActionResult Add(string name, DateTime bDay, int bookId) { if (ModelState.IsValid) { authorRepo.Add(new Author { Name = name, Birthday = bDay }); } return(RedirectToAction("Index", "Book")); }
public void AddAuthor(string nickname, string email, int?votes) { _authorRepository.Add(new Author() { //AuthorId = _authorRepository.NoAuthorsInTable() + 1, Nickname = nickname, Email = email, Votes = votes }); }
public IActionResult Create([FromBody] Author item) { if (item == null) { return(BadRequest()); } _AuthorRepository.Add(item); return(CreatedAtRoute("GetTodo", new { id = item.ID }, item)); }
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); }
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()); }
public Guid Create(CreateAuthorModel model) { var newAuthor = new Author { FirstName = model.FirstName, LastName = model.LastName, DateOfBirth = model.DateOfBirth }; repository.Add(newAuthor); return(newAuthor.AuthorId); }
public int AddAuthor(AddAuthorViewModel addAuthor) { Author author = new Author { FirstName = addAuthor.FirstName, LastName = addAuthor.LastName }; _authorRepository.Add(author); _authorRepository.SaveChange(); return(author.Id); }
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)); }
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()); }
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); }
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); }
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); }
public ActionResult Create(Author entity) { if (ModelState.IsValid) { using (IUnitOfWork uow = uowFactory.Create()) { repository.Add(entity); uow.Save(); return(RedirectToAction("Index")); } } else { return(View()); } }
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 })); }
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(); } }