Пример #1
0
        public async Task <ActionResult <IndividualModel> > Post(IndividualModel model)
        {
            var individual = _mapper.Map <Individual>(model);

            if (model.CityId != 0)
            {
                var city = await _repository.GetCityByIdAsync(model.CityId);

                if (city == null)
                {
                    return(BadRequest(_localizer["City with the given Id could not be found"]));
                }

                individual.City   = city;
                individual.CityId = city.Id;
            }

            _repository.Add(individual);

            if (await _repository.SaveChangesAsync())
            {
                var url = _linkGenerator.GetPathByAction("Get", "Individuals", new
                {
                    id = individual.Id
                });

                return(Created(url, _mapper.Map <IndividualModel>(individual)));
            }

            return(BadRequest());
        }