public async Task <IActionResult> PutCharacterEpisode([FromRoute] int id, [FromBody] CharacterEpisode characterEpisode) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != characterEpisode.Id) { return(BadRequest()); } _context.Entry(characterEpisode).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharacterEpisodeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Character put(Character obj) { entities.Attach(obj); context.Entry(obj).State = EntityState.Modified; context.SaveChanges(); return(obj); }
public ActionResult Edit([Bind(Include = "UserID,UserEmail,Password,firstName,lastName")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(user)); }
//aktualizuje wybrany rekord public async Task <T> UpdateAsync(T updated, int key) { if (updated == null) { throw new ArgumentNullException(nameof(updated)); } _db.Entry(updated).State = EntityState.Modified; await _db.SaveChangesAsync(); return(updated); }
public ActionResult Edit([Bind(Include = "QuestionID,UserID,question,answer")] Questions questions) { Questions tempQuestion = db.Question.Find(questions.QuestionID); if (ModelState.IsValid) { tempQuestion.answer = questions.answer; db.Entry(tempQuestion).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(questions)); }
public IActionResult Post([FromBody] Person person) { // Calling .Add will mark all entities in the graph as Added //_context.People.Add(person); // Calling .Attach will mark all entities in the graph as unmodified //_context.People.Attach(person); // Setting the state of a single entity will not attach related entities //_context.Entry(person).State = EntityState.Added; // Traverse the graph and apply custom rules to decide when // an entity is added, and when it is modified /* * _context.ChangeTracker.TrackGraph(person, * node => * { * if (node.Entry.Entity is Starship) * { * // Existing Starship * if ((node.Entry.Entity as Starship).Id > 0) * { * node.Entry.State = EntityState.Modified; * } * else // New Starship * { * node.Entry.State = EntityState.Added; * } * } * else * { * // Not a Starship (Person?). Assume new * node.Entry.State = EntityState.Added; * } * }); */ try { _context.Entry(person).Property("LastUpdated").CurrentValue = DateTime.Now; _context.SaveChanges(); return(new CreatedAtRouteResult("GetPerson", new { id = person.Id }, person)); } catch (Exception ex) { return(new BadRequestObjectResult(ex.ToString())); } }
public T put(T obj) { entities.Attach(obj); context.Entry(obj).State = EntityState.Modified; return(obj); }