/// <summary> /// Edits the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="model">The model.</param> /// <returns>Task<Model>.</returns> /// <exception cref="System.ApplicationException">车型信息已经存在</exception> public async Task<Model> Edit(int id, Model model) { if (await this.Exist(model)) { throw new ApplicationException("车型信息已经存在"); } using (ChePingContext db = new ChePingContext()) { await db.SaveOrUpdateAsync(model, t => t.Id == id); } return model; }
/// <summary> /// Creates the specified model. /// </summary> /// <param name="model">The model.</param> /// <returns>Task<Model>.</returns> /// <exception cref="System.ApplicationException">车型信息已经存在</exception> public async Task<Model> Create(Model model) { if (await this.Exist(model)) { throw new ApplicationException("车型信息已经存在"); } model.Available = true; using (ChePingContext db = new ChePingContext()) { await db.SaveAsync(model); } return model; }
public async Task<IHttpActionResult> Create(ModelDto dto) { Model model = new Model { Available = true, Brand = dto.Brand, Id = dto.Id, Modeling = dto.Modeling, Price = dto.Price, Series = dto.Series }; if (await this.modelService.Exist(model)) { return this.BadRequest("车型信息已经存在"); } return this.Ok((await this.modelService.Create(model)).ToDto()); }
public async Task<IHttpActionResult> Exist(ModelDto dto) { Model model = new Model { Brand = dto.Brand, Modeling = dto.Modeling, Price = dto.Price, Series = dto.Series }; return this.Ok(new BoolResponse { Result = await this.modelService.Exist(model) }); }
/// <summary> /// Exists the specified model. /// </summary> /// <param name="model">The model.</param> /// <returns>System.Threading.Tasks.Task<ChepingServer.Models.Model>.</returns> public async Task<bool> Exist(Model model) { using (ChePingContext db = new ChePingContext()) { return await db.Models.AnyAsync(m => m.Brand == model.Brand && m.Series == model.Series && m.Modeling == model.Modeling); } }