コード例 #1
0
        public async Task <IActionResult> PutAutoPartsModel(int id, [FromForm] AutoPartsModel autoPartsModel)
        {
            if (id != autoPartsModel.IdSpare)
            {
                return(BadRequest());
            }
            if (autoPartsModel.ImageFile != null)
            {
                DeleteImage(autoPartsModel.ImageName);
                autoPartsModel.ImageName = await SaveImage(autoPartsModel.ImageFile);
            }


            _context.Entry(autoPartsModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AutoPartsModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <AutoPartsModel> > PostAutoPartsModel([FromForm] AutoPartsModel autoPartsModel)
        {
            autoPartsModel.ImageName = await SaveImage(autoPartsModel.ImageFile);

            _context.AutoPartsModel.Add(autoPartsModel);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
            //return CreatedAtAction("GetAutoPartsModel", new { id = autoPartsModel.IdSpare }, autoPartsModel);
        }