public async Task<IHttpActionResult> GetAuthor(int id) { if (id == 0) return BadRequest("id must be higher than 0"); var author = await _repository.GetById(id); var authorModel = new AuthorModel(); return Ok(authorModel.InjectFrom(author)); }
public async Task<IHttpActionResult> SaveAuthor(AuthorModel authorModel) { if (ModelState.IsValid) { var entity = new Author(); entity.InjectFrom(authorModel); return Ok(await _repository.Save(entity)); } var errors = ModelState.Values.SelectMany(x => x.Errors); return BadRequest(Helper.GenerateModelStateError(errors)); }
public async Task<ActionResult> AddAuthor(AuthorModel model) { if (ModelState.IsValid) { var result = await _authorProvider.SaveAuthor(model); var vm = await LoadManageViewModel(); vm.HasChanges = true; vm.Success = result > 0; return View("Index", vm); } return View("Index", await LoadManageViewModel()); }
public Task<int> SaveAuthor(AuthorModel model) { return Save<int, AuthorModel>(model); }