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) }); }
public async Task<IHttpActionResult> Edit([FromUri] int id, OutletDto dto) { Outlet outlet = await this.outletService.Get(id); if (outlet == null) { return this.BadRequest("无此网点,请确认网点id是否正确"); } outlet.Address = dto.Address; outlet.Cellphone = dto.Cellphone; outlet.Contact = dto.Contact; return this.Ok((await this.outletService.Edit(id, outlet)).ToDto()); }