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()); }
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); }