public virtual T Update(T t, object key) { if (t == null) { return(null); } T exist = _context.Set <T>().Find(key); if (exist != null) { _context.Entry(exist).CurrentValues.SetValues(t); _context.SaveChanges(); } return(exist); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSession(int id, Session session) { if (id != session.SessionId) { return(BadRequest()); } _context.Entry(session).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SessionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWorkout(int id, Workout workout) { if (id != workout.WorkoutId) { return(BadRequest()); } _context.Entry(workout).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkoutExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public User UnsubscribeUserFromClass(string userId, int classId) { var user = db.Users.Find(userId); if (user != null) { var tobedeleted = user.Classes.First(c => c.Id == classId); if (tobedeleted != null) { user.Classes.Remove(tobedeleted); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(user); }
//Burde update istedet for delete og inserte... public Instructor UpdateInstuctor(Instructor instructor) { Instructor result = null; if (instructor != null) { var oldvalue = _db.Instructors.First(i => i.InstructorId == instructor.InstructorId); _db.Instructors.Remove(oldvalue); _db.Entry(oldvalue).State = EntityState.Deleted; try { result = _db.Instructors.Add(instructor); _db.Entry(instructor).State = EntityState.Added; _db.SaveChanges(); } catch (Exception e) { //gør noget meaningsfuldt... } } return(result); }
public ActionResult Edit([Bind(Include = "Id,type,duration,caloriesBurnt,startTime")] Workout workout) { if (Session["user"] == null) { return(Redirect("/")); } if (ModelState.IsValid) { db.Entry(workout).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workout)); }
public ActionResult Edit([Bind(Include = "Id,fName,lName,password")] User user) { if (Session["user"] == null) { return(Redirect("/")); } if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); List <User> list = new List <User>(); list.Add(user); return(View("Index", list)); } return(View(user)); }
public void Put(int id, [FromBody] Exercise exercise) { exercise.ExerciseId = id; _db.Entry(exercise).State = EntityState.Modified; _db.SaveChanges(); }