Esempio n. 1
0
        public async Task <Result> Put(int id, [FromBody] CountryCreateParam model)
        {
            var country = await _countryRepository.FirstOrDefaultAsync(id);

            if (country == null)
            {
                throw new Exception("国家不存在");
            }
            var any = _countryRepository.Query().Any(c =>
                                                     (c.NumericIsoCode == model.NumericIsoCode ||
                                                      c.TwoLetterIsoCode == model.TwoLetterIsoCode ||
                                                      c.ThreeLetterIsoCode == model.ThreeLetterIsoCode) &&
                                                     c.Id != id);

            if (any)
            {
                return(Result.Fail("国家编码已存在"));
            }
            country.DisplayOrder       = model.DisplayOrder;
            country.NumericIsoCode     = model.NumericIsoCode;
            country.ThreeLetterIsoCode = model.ThreeLetterIsoCode;
            country.TwoLetterIsoCode   = model.TwoLetterIsoCode;
            country.Name              = model.Name;
            country.IsBillingEnabled  = model.IsBillingEnabled;
            country.IsCityEnabled     = model.IsCityEnabled;
            country.IsDistrictEnabled = model.IsDistrictEnabled;
            country.IsPublished       = model.IsPublished;
            country.IsShippingEnabled = model.IsShippingEnabled;
            country.UpdatedOn         = DateTime.Now;
            await _countryRepository.SaveChangesAsync();

            return(Result.Ok());
        }
Esempio n. 2
0
        public async Task <Result> Post([FromBody] CountryCreateParam model)
        {
            var any = _countryRepository.Query().Any(c => c.NumericIsoCode == model.NumericIsoCode ||
                                                     c.TwoLetterIsoCode == model.TwoLetterIsoCode ||
                                                     c.ThreeLetterIsoCode == model.ThreeLetterIsoCode);

            if (any)
            {
                return(Result.Fail("国家编码已存在"));
            }
            var country = new Country()
            {
                DisplayOrder       = model.DisplayOrder,
                NumericIsoCode     = model.NumericIsoCode,
                ThreeLetterIsoCode = model.ThreeLetterIsoCode,
                TwoLetterIsoCode   = model.TwoLetterIsoCode,
                Name              = model.Name,
                IsBillingEnabled  = model.IsBillingEnabled,
                IsCityEnabled     = model.IsCityEnabled,
                IsDistrictEnabled = model.IsDistrictEnabled,
                IsPublished       = model.IsPublished,
                IsShippingEnabled = model.IsShippingEnabled
            };

            _countryRepository.Add(country);
            await _countryRepository.SaveChangesAsync();

            return(Result.Ok());
        }