Example #1
0
        /// <summary>
        ///     Edits the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="model">The model.</param>
        /// <returns>Task&lt;Model&gt;.</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;
        }
Example #2
0
        /// <summary>
        ///     Creates the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>Task&lt;Model&gt;.</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;
        }
Example #3
0
        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());
        }
Example #4
0
        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) });
        }
Example #5
0
 /// <summary>
 ///     Exists the specified model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>System.Threading.Tasks.Task&lt;ChepingServer.Models.Model&gt;.</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);
     }
 }