Example #1
0
        public async Task <IActionResult> CreateOne([FromBody] StandardComponent standardComponent)
        {
            if (ModelState.IsValid)
            {
                standardComponent.Id = DataUtil.GenerateUniqueId();
                await _standardRepository.AddAsync(standardComponent);

                _logger.Info("Created standard component: {@standardComponent}", standardComponent);
                return(Ok(standardComponent.Id));
            }

            return(BadRequest());
        }
Example #2
0
        public virtual async Task <Model> AddAsync(Model modelToAdd)
        {
            try
            {
                await standardRepository.AddAsync(modelToAdd);

                await unitOfWork.CompleteAsync();
            }
            catch (DbUpdateException e)
            {
                // Return a bad request if insert fails
                throw new BadRequestException(e.InnerException?.Message, typeof(Model).ToString());
            }
            return(modelToAdd);
        }