コード例 #1
0
        public async Task <Result> IsValidAsync(BookDefResourceClient res)
        {
            var writers = await writerRepo.GetAll();

            if (!writers.Any(a => a.Id == res.WriterId))
            {
                return(Result.Fail("You must give a valid writer id to create a book definition"));
            }

            return(Result.Succeed());
        }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] BookDefResourceClient res)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Result isValid = await cliValidator.IsValidAsync(res);

            if (!isValid.Success)
            {
                return(BadRequest(isValid.ErrorMessage));
            }

            var bookDef = this.mapper.Map <BookDefResourceClient, BookDef>(res);

            this.repo.Create(bookDef);

            return(Ok());
        }
コード例 #3
0
        public async Task <IActionResult> Update(int id, [FromBody] BookDefResourceClient res)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var toUpdate = await getBookDef(id);

            var bookDef = this.mapper.Map <BookDefResourceClient, BookDef>(res);

            toUpdate.Name        = bookDef.Name;
            toUpdate.YearWritten = bookDef.YearWritten;

            toUpdate = bookDef;

            await uow.CompleteAsync();

            return(Ok());
        }