예제 #1
0
        public IActionResult CreateGhostbuster([FromBody] GhostbusterInputModel ghostbuster)
        {
            if (!ModelState.IsValid)
            {
                throw new ModelFormatException(ModelState.RetrieveErrorString());
            }
            var newId = _ghostbusterService.CreateGhostbuster(ghostbuster);

            return(CreatedAtRoute("GetGhostbusterById", new { id = newId }, null));
        }
예제 #2
0
        public int CreateGhostbuster(GhostbusterInputModel ghostbuster)
        {
            var nextId = _dbContext.Ghostbusters.Count() + 1;

            _dbContext.Ghostbusters.Add(new Ghostbuster
            {
                Id        = nextId,
                Name      = ghostbuster.Name,
                Expertize = ghostbuster.Expertize
            });
            return(nextId);
        }
예제 #3
0
        /// <summary>
        /// Determines if provided expertize for model is valid
        /// </summary>
        /// <param name="value"></param>
        /// <param name="validationContext"></param>
        /// <returns>Validation result - indicates success if expertize property was valid otherwise failure</returns>
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            GhostbusterInputModel ghostbuster = (GhostbusterInputModel)validationContext.ObjectInstance;

            if (_validExpertizes.FirstOrDefault(x => x == ghostbuster.Expertize) == null)
            {
                return(new ValidationResult(GetErrorMessage(ghostbuster.Expertize)));
            }
            else
            {
                return(ValidationResult.Success);
            }
        }
 public int CreateGhostbuster(GhostbusterInputModel ghostbuster) => _ghostbusterRepository.CreateGhostbuster(ghostbuster);