示例#1
0
        public ActionResult <CountryDetail> CreateCountry(CountryCreate countryDTO)
        {
            var country = this.mapper.Map <Country>(countryDTO);

            country = this.subNineRepository.Create(country);

            return(this.mapper.Map <CountryDetail>(country));
        }
        public static CountryCreate.Response Handle(IRepository repository, CountryCreate.Request request)
        {
            var validationDetails = Validator.ValidateRequest(request);
            if (validationDetails.HasValidationIssues)
                return new CountryCreate.Response(validationDetails: validationDetails);

            var country = new Country(request.CommandModel.Name, request.CommandModel.Population);
            repository.Add(country);
            repository.Save();

            return new CountryCreate.Response(country.Id);
        }
        public async Task<HttpResponseMessage> AddCountry(CountryCreate.CommandModel commandModel)
        {
            var request = new CountryCreate.Request(SystemPrincipal.Name, commandModel);
            var response = await DomainServices.CallServiceAsync<CountryCreate.Response>(request);

            var keyPairs = response.ValidationDetails.AsKeyValuePairs();
            return Request.CreateResponse(HttpStatusCode.OK, new
            {
                response.Id,
                ErrorMessages = keyPairs,
                BigErrorMessage = keyPairs.Any()
                    ? keyPairs.Select(p => p.Value).Aggregate((l, r) => $"{l}{Environment.NewLine}{r}")
                    : null,
            });
        }
示例#4
0
        public bool CreateCountry(CountryCreate model)
        {
            var entity =
                new Country()
            {
                UserId      = _userId,
                CountryName = model.CountryName,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Countries.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }