コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        //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);
        }
コード例 #7
0
 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));
 }
コード例 #8
0
 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));
 }
コード例 #9
0
 public void Put(int id, [FromBody] Exercise exercise)
 {
     exercise.ExerciseId       = id;
     _db.Entry(exercise).State = EntityState.Modified;
     _db.SaveChanges();
 }