コード例 #1
0
        public async Task Update(City entity)
        {
            var model = _mapper.Map <Models.City>(entity);

            _context.Entry(model).Property(e => e.Name).IsModified        = true;
            _context.Entry(model).Property(e => e.Description).IsModified = true;
            await _context.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <int> CreateAsync(CityDto cityDto)
        {
            if (cityDto != null &&
                string.IsNullOrWhiteSpace(cityDto.Name) == false)
            {
                // depending on the business rules, vaidate the DTO.
                var city = cityDto.ToCity();
                _citiesContext.Cities.Add(city);
                await _citiesContext.SaveChangesAsync();

                return(city.Id);
            }
            return(-1);
        }