コード例 #1
0
        public ActionResult <CategoryReadModel> Add(Input.CategoryCreateModel category)
        {
            //Basic Validatation happens through Annotations on Create Command Model

            if (!_service.Add(category, out var createdCategory))
            {
                return(new NoContentResult());
            }

            //TODO: Don't leak the database Id, rather use the restful entity id
            return(CreatedAtRoute(nameof(LookupCategory), new { Id = createdCategory.Id }, createdCategory));
        }
コード例 #2
0
        public bool Add(Input.CategoryCreateModel category, out CategoryReadModel createdCategory)
        {
            var commandDatabaseModel = _mapper.Map <Database.CategoryModel>(category);

            try
            {
                _repository.Create(commandDatabaseModel);
                _repository.SaveChanges();
            }
            catch (Exception exception)
            {
                //TODO: Beef this up for real production environment
                _logger.LogError("Something went Boom", exception);
                createdCategory = null;
                return(false);
            }

            createdCategory = _mapper.Map <CategoryReadModel>(commandDatabaseModel);
            return(true);
        }