コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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());
        }
コード例 #4
0
 public Task<int> SaveAuthor(AuthorModel model)
 {
     return Save<int, AuthorModel>(model);
 }