public async Task UpdateAsync(int id, AuthorInputModel authorInputModel) { var author = mapper.Map <Author>(authorInputModel); author.AuthorId = id; await repository.UpdateAsync(author); }
public AuthorDto CreateAuthor(AuthorInputModel author) { int nextInt = 0; if (AuthorDataProvider.Authors.Count == 0) { nextInt = 1; } else { nextInt = AuthorDataProvider.Authors.OrderByDescending(a => a.Id).FirstOrDefault().Id + 1; } var entity = new Author { Id = nextInt, Name = author.Name, ProfileImgSource = author.ProfileImgSource, Bio = author.Bio, ModifiedBy = "Admin", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; AuthorDataProvider.Authors.Add(entity); return(new AuthorDto { Id = entity.Id, Name = entity.Name }); }
public async Task <IActionResult> Edit(int id, AuthorInputModel authorModel) { if (!this.ModelState.IsValid) { return(this.View(authorModel)); } var result = await this.authorService.EditAsync( id, authorModel.FirstName, authorModel.LastName); if (result == false) { this.TempData.AddErrorMessage(WebAdminConstants.AuthorNotEdited); return(RedirectToAction(nameof(Index))); } this.TempData.AddSuccessMessage(string.Format( WebAdminConstants.AuthorUpdated, authorModel.FirstName, authorModel.LastName)); return(this.RedirectToAction(nameof(Index))); }
public int CreateNewAuthor(AuthorInputModel author) { var entity = ToAuthor(author); _dataContext.getAuthors.Add(entity); return(entity.Id); }
// PUT: api/Authors/5 /// <summary> /// Funkcja do edycji autora o podanym ID /// </summary> /// <param name="id"></param> /// <param name="inputModel"></param> /// <returns></returns> public async Task <IHttpActionResult> PutAuthor(int id, AuthorInputModel inputModel) { if (inputModel == null) { return(BadRequest(message: "empty")); } if (id != inputModel.ID) { return(BadRequest()); } var author = await _authorRepository.GetByIdAsync(id); if (author == null) { return(NotFound()); } author.FirstName = inputModel.FirstName; author.LastName = inputModel.LastName; var result = await _authorRepository.SaveAsync(author); if (!result) { return(InternalServerError()); } return(Ok()); }
/* From teacher: * "Betri leið væri að sækja stærsta Id * og incrementa það þegar verið er að vinna með lista." */ private Author ToAuthor(AuthorInputModel author) { var entity = Mapper.Map <Author>(author); entity.Id = _dataContext.getAuthors.Max(a => a.Id) + 1; return(entity); }
public AuthorDto CreateAuthor(AuthorInputModel author) { var nextId = DataProvider.Authors.Count() + 1; var entity = ToAuthor(author, nextId); DataProvider.Authors.Add(entity); return(ToAuthorDto(entity)); }
public void UpdateAuthorById(AuthorInputModel author, int authorId) { var updateAuthor = _dataContext.getAuthors.FirstOrDefault(a => a.Id == authorId); updateAuthor.Name = author.Name; updateAuthor.Bio = author.Bio; updateAuthor.ProfileImgSource = author.ProfileImgSource; }
public void updateAuthor(int authorId, [FromBody] AuthorInputModel inputModel) { if (!ModelState.IsValid) { throw new ModelFormatException(); } _authorService.updateAuthorById(inputModel, authorId); }
public IActionResult ChangeAuthor(AuthorInputModel author) { if (ModelState.IsValid) { _authorService.UpdateAuthor(author); } return(RedirectToAction("ChangeAuthor")); }
public async Task <AuthorViewModel> AddAsync(AuthorInputModel authorInputModel) { var author = mapper.Map <Author>(authorInputModel); var result = await repository.AddAsync(author); var authorViewModel = mapper.Map <AuthorViewModel>(result); return(authorViewModel); }
public IActionResult CreateAuthor([FromBody] AuthorInputModel author) { if (ModelState.IsValid) { int id = _authorService.CreateAuthor(author); return(CreatedAtRoute("GetAuthorById", new { id }, null)); } return(StatusCode(412, author)); }
public IActionResult UpdateAuthor([FromBody] AuthorInputModel body, int authorId) { if (!ModelState.IsValid) { throw new ModelFormatException("Model not properly formatted"); } _authorsService.UpdateAuthor(body, authorId); return(NoContent()); }
public AuthorDto CreateAuthor(AuthorInputModel body) { var entity = _mapper.Map <Author>(body); var nextId = AuthorDataProvider.Authors.Last().Id + 1; entity.Id = nextId; AuthorDataProvider.Authors.Add(entity); return(_mapper.Map <AuthorDto>(entity)); }
public AuthorViewModel Post(AuthorInputModel authorInputModel) { var author = _mapper.Map <Author>(authorInputModel); _uow.AuthorRepository.Add(author); _uow.Commit(); return(_mapper.Map <AuthorViewModel>(author)); }
public IActionResult AddAuthor(AuthorInputModel model) { if (ModelState.IsValid) { _bookService.AddAuthor(model); return(Ok()); } return(BadRequest()); }
public IActionResult EditAuthor(int id, [FromBody] AuthorInputModel author) { if (!ModelState.IsValid) { throw new InputFormatException("Author input model was not properly formatted."); } _authorService.UpdateAuthorById(author, id); return(NoContent()); }
public AuthorViewModel Put(int id, AuthorInputModel authorInputModel) { var author = _mapper.Map <Author>(authorInputModel); _uow.AuthorRepository.Update(author); _uow.Commit(); return(_mapper.Map <AuthorViewModel>(author)); }
public IActionResult UpdateAuthorById([FromBody] AuthorInputModel author, int authorId) { if (!ModelState.IsValid) { throw new ModelFormatException("Author was not properly formatted"); } _authorService.UpdateAuthorById(author, authorId); return(NoContent()); }
public AuthorDto CreateNewAuthor(AuthorInputModel author) { var nextId = DataProvider.Authors.OrderByDescending(r => r.Id).FirstOrDefault().Id + 1; var entity = _mapper.Map <Author>(author); entity.Id = nextId; DataProvider.Authors.Add(entity); return(_mapper.Map <AuthorDto>(entity)); }
public int CreateAuthor(AuthorInputModel author) { var nextId = DataProvider.Authors.Count() + 1; var entity = Mapper.Map <Author>(author); entity.Id = nextId; DataProvider.Authors.Add(entity); return(nextId); }
public Boolean UpdateAuthorById(int id, AuthorInputModel category, string urlStr) { if (_authorRepository.GetAuthorDetailById(id, urlStr) == null) { return(false); } _authorRepository.UpdateAuthorById(id, category); return(true); }
public int CreateAuthor(AuthorInputModel author) { int nextId = DataContext.Authors.Max(x => x.Id) + 1; Author authorToAdd = Mapper.Map <Author>(author); authorToAdd.Id = nextId; DataContext.Authors.Add(authorToAdd); return(nextId); }
public IActionResult AddAuthor(AuthorInputModel author) { if (ModelState.IsValid) { _authorService.AddAuthor(author); } return(RedirectToAction("AddAuthor")); }
public void AddAuthor(AuthorInputModel author) { var authorEntity = new Author { Name = author.Name }; _bookRepo.AddAuthor(authorEntity); }
public ActionResult Put(int id, [FromBody] AuthorInputModel author) { if (id != author.Id) { return(BadRequest()); } var result = _authorService.Put(id, author); return(new CreatedAtRouteResult("GetAuthorsDetails", new { id = result.Id }, result)); }
public IActionResult AddAuthor(AuthorInputModel input) { if (!input.IsValid()) { return(BadRequest(input.ValidationMessage)); } var author = _authorAppService.Add(input); return(Created(new Uri($"{Request.Path}/{author.Id}", UriKind.Relative), author)); }