예제 #1
0
 /// <summary>
 ///     Exists the specified city.
 /// </summary>
 /// <param name="city">The city.</param>
 /// <returns>Task&lt;System.Boolean&gt;.</returns>
 public async Task<bool> Exist(City city)
 {
     using (ChePingContext db = new ChePingContext())
     {
         return await db.Cities.AnyAsync(c => c.ProvinceName == city.ProvinceName && c.CityName == city.CityName);
     }
 }
예제 #2
0
        public async Task<IHttpActionResult> Exist(CityDto dto)
        {
            City city = new City
            {
                CityName = dto.CityName,
                ProvinceName = dto.ProvinceName
            };

            return this.Ok(new BoolResponse { Result = await this.cityService.Exist(city) });
        }
예제 #3
0
        /// <summary>
        ///     Creates the specified city.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <returns>Task&lt;City&gt;.</returns>
        /// <exception cref="ApplicationException">城市信息已经存在</exception>
        public async Task<City> Create(City city)
        {
            if (await this.Exist(city))
            {
                throw new ApplicationException("城市信息已经存在");
            }

            using (ChePingContext db = new ChePingContext())
            {
                await db.SaveAsync(city);
            }

            return city;
        }
예제 #4
0
        public async Task<IHttpActionResult> Create(CityDto dto)
        {
            City city = new City
            {
                CityName = dto.CityName,
                ProvinceName = dto.ProvinceName
            };

            if (await this.cityService.Exist(city))
            {
                return this.BadRequest("城市信息已经存在");
            }

            return this.Ok((await this.cityService.Create(city)).ToDto());
        }