/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="outlet">The outlet.</param> /// <returns>Task<Outlet>.</returns> public async Task<Outlet> Edit(int id, Outlet outlet) { using (ChePingContext db = new ChePingContext()) { await db.SaveOrUpdateAsync(outlet, o => o.Id == id); } return outlet; }
/// <summary> /// Creates the specified outlet. /// </summary> /// <param name="outlet">The outlet.</param> /// <returns>Task<Outlet>.</returns> /// <exception cref="System.ApplicationException">网点信息已经存在</exception> /// <exception cref="ApplicationException">网点信息已经存在</exception> public async Task<Outlet> Create(Outlet outlet) { if (await this.Exist(outlet)) { throw new ApplicationException("网点信息已经存在"); } outlet.Available = true; using (ChePingContext db = new ChePingContext()) { await db.SaveAsync(outlet); } return outlet; }
public async Task<IHttpActionResult> Create(OutletDto dto) { Outlet outlet = new Outlet { Available = true, Address = dto.Address, Cellphone = dto.Cellphone, CityId = dto.CityId, Contact = dto.Contact, OutletName = dto.OutletName }; if (await this.outletService.Exist(outlet)) { return this.BadRequest("网点信息已经存在"); } //if not exist, retrieve the city data by cityId and add it to outlet entity. City city = await this.cityService.Get(outlet.CityId); outlet.CityName = city.CityName; outlet.ProvinceName = city.ProvinceName; return this.Ok((await this.outletService.Create(outlet)).ToDto()); }
public async Task<IHttpActionResult> Exist(OutletDto dto) { Outlet outlet = new Outlet { CityId = dto.CityId, OutletName = dto.OutletName }; return this.Ok(new BoolResponse { Result = await this.outletService.Exist(outlet) }); }
/// <summary> /// Exists the specified outlet. /// </summary> /// <param name="outlet">The outlet.</param> /// <returns>Task<System.Boolean>.</returns> public async Task<bool> Exist(Outlet outlet) { using (ChePingContext db = new ChePingContext()) { //use cityId and outletName to match return await db.Outlets.AnyAsync(o => o.CityId == outlet.CityId && o.OutletName == outlet.OutletName); } }