예제 #1
0
        public async Task <IActionResult> Create([FromBody] BookInstResource bookInstRes)
        {
            var valResult = await resourceClientValidator.IsValidAsync(bookInstRes);

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

            // Redundant alanları set edelim tanımlardan
            var bookInst = mapper.Map <BookInstResource, BookInst>(bookInstRes);
            var defs     = await definitionRepo.GetAll();

            bookInst.WriterName = defs.FirstOrDefault(a => a.Id == bookInst.DefinitionId).Writer.Name;
            bookInst.BookName   = defs.FirstOrDefault(a => a.Id == bookInst.DefinitionId).Name;

            repo.Create(bookInst);

            var bookInsts = await this.repo.GetAll();

            var justCreated = bookInsts.Where(a => a.Definition.Name == bookInst.Definition.Name);

            return(Ok(justCreated));
        }