public async Task <IActionResult> PutContact(int id, Contact contact) { if (id != contact.Id) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public async Task <IActionResult> PutContactItem([FromForm] ContactItem item, long id, IFormFile profileImage) { if (id != item.Id) { return(BadRequest()); } if (profileImage != null && profileImage.Length > 0) { item.ProfileImage = handleFile(profileImage); } _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> PutSkills([FromRoute] int id, [FromBody] EditSkillModel skills) { //In this api we are using this type of model that complicates the code, because swagger generates the // scheme in the documentation more precise with this one if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != skills.SkillId) { return(BadRequest("No SkillID is added or the added one is wrong")); } _context.Entry(new SkillModel() { SkillId = skills.SkillId, SkillName = skills.SkillName }).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception e) { if (!SkillsExists(id)) { return(NotFound("The record with id " + id + " does not exist in the database")); } else { return(BadRequest(e.InnerException.Message)); } } return(Ok("Success")); }