コード例 #1
0
        public async Task <ActionResult <CampModel> > Put(
            [FromServices] IMonikerSettings monikerSettings,
            [FromServices] IMonikerRuleProcessor monikerRuleProcessor,
            string moniker,
            CampModel model)
        {
            try
            {
                if (!monikerSettings.PutEnabled)
                {
                    return(this.StatusCode(StatusCodes.Status403Forbidden, "Update disable on API..."));
                }

                var checkResults = await monikerRuleProcessor.PassesAllRulesAsync(model);

                if (!checkResults.Passed)
                {
                    return(this.StatusCode(StatusCodes.Status406NotAcceptable, checkResults.Errors));
                }

                var oldCamp = await _repository.GetCampAsync(moniker);

                if (oldCamp == null)
                {
                    return(NotFound($"Could not find camp with moniker of {moniker}"));
                }

                _mapper.Map(model, oldCamp);

                if (await _repository.SaveChangesAsync())
                {
                    return(_mapper.Map <CampModel>(oldCamp));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
コード例 #2
0
 public AlphaNumericNameRule(IMonikerSettings configuration)
 {
     _configuration = configuration;
 }
コード例 #3
0
 public UpperCaseNameRule(IMonikerSettings configuration)
 {
     _configuration = configuration;
 }