Example #1
0
        private ApplicationUser CreateToken(ApplicationUser user)
        {
            var token = CryptoUtils.CreateToken(user.Id);

            user.Token      = token;
            user.TimeToLive = DateUtils.TimeStampOneDay;
            _userContext.Update(user);
            _userContext.SaveChanges();
            return(user);
        }
Example #2
0
        //public void Add(int userid, WorkoutVM model)
        //{
        //    var workout = new Workout(userid, model.starttime, model.endtime);
        //    List<WorkoutExcercise> exList = new List<WorkoutExcercise>();

        //    foreach (var exercise in model.exercises)
        //    {
        //        exList.Add(new WorkoutExcercise(workout, exercise));
        //    }

        //    workout.Excercises = exList;

        //    _context.Add(workout);
        //    _context.SaveChanges();
        //}

        public void Update(WorkoutVM model)
        {
            var workout = _context.Workouts.Find(model.id);

            workout.StartTime = model.starttime;
            workout.EndTime   = model.endtime;

            foreach (var exercise in model.exercises)
            {
                if (!workout.Excercises.Any(e => e.ExcerciseId == exercise.Id))
                {
                    var newexercise = _context.Excercises.Find(exercise.Id);

                    workout.Excercises.Add(new WorkoutExcercise(workout, newexercise));
                }
            }

            _context.Update(workout);
            _context.SaveChanges();
        }