コード例 #1
0
ファイル: CityService.cs プロジェクト: votrongdao/cheping
 /// <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
ファイル: CityController.cs プロジェクト: votrongdao/cheping
        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
ファイル: CityService.cs プロジェクト: votrongdao/cheping
        /// <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
ファイル: CityController.cs プロジェクト: votrongdao/cheping
        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());
        }