public async Task <IActionResult> Edit(int id, [Bind("WorkoutLogId,WorkoutDate,ExerciseId")] WorkoutLog workoutLog)
        {
            if (id != workoutLog.WorkoutLogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(workoutLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WorkoutLogExists(workoutLog.WorkoutLogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(workoutLog));
        }
示例#2
0
        public ActionResult DeleteLog(WorkoutLog workoutLog)
        {
            db.Entry(workoutLog).State = EntityState.Deleted;
            db.SaveChanges();

            return(RedirectToAction("WorkoutLog"));
        }
 public WorkoutLogDTO(WorkoutLog wl)
 {
     foreach (var propertyInfo in typeof(WorkoutLog).GetProperties())
     {
         propertyInfo.SetValue(this, propertyInfo.GetValue(wl));
     }
 }
示例#4
0
        public bool Delete(int ID)
        {
            WorkoutLog workoutLog = db.WorkoutLogs.First(x => x.ID == ID);

            db.WorkoutLogs.Remove(workoutLog);
            db.SaveChanges();
            return(true);
        }
示例#5
0
        public bool Add(WorkoutLogDetailDTO entity)
        {
            WorkoutLog workoutLog = new WorkoutLog();

            workoutLog.MemberID  = (int)entity.MemberID;
            workoutLog.WorkoutID = (int)entity.WorkoutID;
            workoutLog.EditTime  = entity.EditTime;
            //workoutLog.Workout.Name = entity.WorkoutName;
            workoutLog.WorkoutHours = entity.WorkoutHours;
            return(dao.Add(workoutLog));
        }
        public async Task <IActionResult> Create([Bind("WorkoutLogId,WorkoutDate,ExerciseId")] WorkoutLog workoutLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(workoutLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(workoutLog));
        }
示例#7
0
        public ActionResult EditLog(WorkoutLog workoutLog)
        {
            var workoutRef = db.WorkoutRefs.Find(workoutLog.WorkoutRefId);

            workoutLog.Calories = workoutRef.Calories * workoutLog.Qty;

            db.Entry(workoutLog).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("WorkoutLog"));
        }
示例#8
0
 //is workout null
 public bool CreateWorkoutLog(WorkoutLogDTO workout)
 {
     using (var dbTransaction = db.Database.BeginTransaction())
     {
         try
         {
             int getUserID = (from cred in db.Credentials
                              where workout.userName == cred.UserName
                              select cred.UserID).FirstOrDefault();
             WorkoutLog work = new WorkoutLog
             {
                 UserID      = getUserID,
                 WorkoutType = workout.WorkoutType,
                 Date_Time   = workout.Date_Time,
             };
             db.Workouts.Add(work);
             if (workout.WorkoutType.Equals("Cardio"))
             {
                 Cardio card = new Cardio
                 {
                     CardioType = workout.CardioType,
                     Distance   = workout.Distance,
                     Time       = workout.Time
                 };
                 db.Cardios.Add(card);
             }
             else if (workout.WorkoutType.Equals("WeightLifting"))
             {
                 WeightLifting weight = new WeightLifting
                 {
                     LiftingType = workout.LiftingType,
                     Reps        = workout.Reps,
                     Sets        = workout.Sets
                 };
                 db.WeightLiftings.Add(weight);
             }
             //add into database t he new instance and saves
             db.SaveChanges();
             dbTransaction.Commit();
             return(true);
         }
         catch (SqlException)
         {
             dbTransaction.Rollback();
             return(false);
         }
         catch (DataException)
         {
             dbTransaction.Rollback();
             return(false);
         }
     }
 }
示例#9
0
        public void UpDate(WorkoutLogDetailDTO entity)
        {
            WorkoutLog workoutLog = new WorkoutLog();

            workoutLog.ID        = entity.ID;
            workoutLog.MemberID  = (int)entity.MemberID;
            workoutLog.WorkoutID = (int)entity.WorkoutID;
            workoutLog.EditTime  = entity.EditTime;
            //workoutLog.Workout.Name = entity.WorkoutName;
            workoutLog.WorkoutHours = entity.WorkoutHours;
            dao.Update(workoutLog);
        }
示例#10
0
        public void Update(WorkoutLog entity)
        {
            WorkoutLog workoutLog = db.WorkoutLogs.First(x => x.ID == entity.ID);

            workoutLog.MemberID = entity.MemberID;
            //workoutLog.Member.Name = entity.Member.Name;
            workoutLog.WorkoutID = entity.WorkoutID;
            //workoutLog.Workout.Name = entity.Workout.Name;
            workoutLog.EditTime     = entity.EditTime;
            workoutLog.WorkoutHours = entity.WorkoutHours;
            //workoutLog.Workout.Calories = entity.Workout.Calories;
            db.SaveChanges();
        }
示例#11
0
 public bool CreateWorkout()
 {
     using (var dbTransaction = db.Database.BeginTransaction())
     {
         try
         {
             WorkoutLog w = new WorkoutLog
             {
                 UserID      = 1,
                 WorkoutType = "WeightLifting",
                 Date_Time   = new DateTime(2015, 12, 12)
             };
             db.Workouts.Add(w);
             if (w.WorkoutType.Equals("Cardio"))
             {
                 Cardio card = new Cardio
                 {
                     CardioType = "sprinting",
                     Distance   = 12.21,
                     Time       = "12:32"
                 };
                 db.Cardios.Add(card);
             }
             else if (w.WorkoutType.Equals("WeightLifting"))
             {
                 WeightLifting weight = new WeightLifting
                 {
                     LiftingType = "Curls",
                     Reps        = 12,
                     Sets        = 11
                 };
                 db.WeightLiftings.Add(weight);
             }
             //add into database t he new instance and saves
             db.SaveChanges();
             dbTransaction.Commit();
             return(true);
         }
         catch (SqlException)
         {
             dbTransaction.Rollback();
             return(false);
         }
         catch (DataException)
         {
             dbTransaction.Rollback();
             return(false);
         }
     }
 }
 internal bool Add(WorkoutLog entity)
 {
     try
     {
         db.WorkoutLogs.Add(entity);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
        internal bool Delete(WorkoutLog entity)
        {
            WorkoutLog oldEntity = db.WorkoutLogs.Where(wl => wl.ID == entity.ID).SingleOrDefault();

            try
            {
                db.WorkoutLogs.Remove(oldEntity);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
        internal bool Edit(WorkoutLog entity)
        {
            WorkoutLog oldEntity = db.WorkoutLogs.Where(wl => wl.ID == entity.ID).SingleOrDefault();

            try
            {
                oldEntity.WorkoutID    = entity.WorkoutID;
                oldEntity.EditTime     = entity.EditTime;
                oldEntity.WorkoutHours = entity.WorkoutHours;
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
示例#15
0
 public bool IsWorkoutLogExist(int ID)
 {
     try
     {
         WorkoutLog workoutLog = db.WorkoutLogs.FirstOrDefault(x => x.ID == ID);
         if (workoutLog != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#16
0
        public async Task SaveWorkoutRecordsAsync(IList <WorkoutData> dataCollection)
        {
            IList <WorkoutLog> workoutLogCollection = new List <WorkoutLog>();

            foreach (var data in dataCollection)
            {
                var workoutLog = new WorkoutLog()
                {
                    ActivityName = data.ActivityName,
                    CreatedOn    = data.CreatedOn,
                    Repeatations = data.Repeatations,
                    SetNumber    = data.SetNumber
                };

                workoutLogCollection.Add(workoutLog);
            }

            await _context.Workouts.AddRangeAsync(workoutLogCollection);

            await _context.SaveChangesAsync();
        }
示例#17
0
        public ActionResult Log(Workout workout)
        {
            var user = db.Users.Where(e => e.UserName == HttpContext.User.Identity.Name).FirstOrDefault();

            if (workout.Duration.HasValue && workout.Duration.Value > 0)
            {
                var workoutRef = db.WorkoutRefs.Where(e => e.Id == workout.DurationId).FirstOrDefault();

                var workoutLog = new WorkoutLog();
                workoutLog.Qty          = workout.Duration.Value;
                workoutLog.UserId       = user.Id;
                workoutLog.WorkoutDate  = Convert.ToDateTime(workout.WorkoutDate);
                workoutLog.WorkoutRefId = workoutRef.Id;
                workoutLog.Calories     = workoutRef.Calories * workout.Duration.Value;

                db.Entry(workoutLog).State = System.Data.EntityState.Added;
                db.SaveChanges();
            }

            if (workout.Rep.HasValue && workout.Rep.Value > 0)
            {
                var workoutRef = db.WorkoutRefs.Where(e => e.Id == workout.RepId).FirstOrDefault();

                var workoutLog = new WorkoutLog();
                workoutLog.Qty          = workout.Rep.Value;
                workoutLog.UserId       = user.Id;
                workoutLog.WorkoutDate  = Convert.ToDateTime(workout.WorkoutDate);
                workoutLog.WorkoutRefId = workoutRef.Id;
                workoutLog.Calories     = workoutRef.Calories * workout.Rep.Value;

                db.Entry(workoutLog).State = System.Data.EntityState.Added;
                db.SaveChanges();
            }

            return(RedirectToAction("WorkoutLog"));
        }
        public ActionResult DeleteLog(WorkoutLog workoutLog)
        {
            db.Entry(workoutLog).State = EntityState.Deleted;
            db.SaveChanges();

            return RedirectToAction("WorkoutLog");
        }
        public ActionResult Log(Workout workout)
        {
            var user = db.Users.Where(e => e.UserName == HttpContext.User.Identity.Name).FirstOrDefault();

            if (workout.Duration.HasValue && workout.Duration.Value > 0)
            {
                var workoutRef = db.WorkoutRefs.Where(e => e.Id == workout.DurationId).FirstOrDefault();

                var workoutLog = new WorkoutLog();
                workoutLog.Qty = workout.Duration.Value;
                workoutLog.UserId = user.Id;
                workoutLog.WorkoutDate = Convert.ToDateTime(workout.WorkoutDate);
                workoutLog.WorkoutRefId = workoutRef.Id;
                workoutLog.Calories = workoutRef.Calories * workout.Duration.Value;

                db.Entry(workoutLog).State = System.Data.EntityState.Added;
                db.SaveChanges();
            }

            if (workout.Rep.HasValue && workout.Rep.Value > 0)
            {
                var workoutRef = db.WorkoutRefs.Where(e => e.Id == workout.RepId).FirstOrDefault();

                var workoutLog = new WorkoutLog();
                workoutLog.Qty = workout.Rep.Value;
                workoutLog.UserId = user.Id;
                workoutLog.WorkoutDate = Convert.ToDateTime(workout.WorkoutDate);
                workoutLog.WorkoutRefId = workoutRef.Id;
                workoutLog.Calories = workoutRef.Calories * workout.Rep.Value;

                db.Entry(workoutLog).State = System.Data.EntityState.Added;
                db.SaveChanges();
            }

            return RedirectToAction("WorkoutLog");
        }
        public ActionResult EditLog(WorkoutLog workoutLog)
        {
            var workoutRef = db.WorkoutRefs.Find(workoutLog.WorkoutRefId);
            workoutLog.Calories = workoutRef.Calories * workoutLog.Qty;

            db.Entry(workoutLog).State = EntityState.Modified;
            db.SaveChanges();

            return RedirectToAction("WorkoutLog");
        }
示例#21
0
 internal bool Add(WorkoutLog entity)
 {
     return(dao.Add(entity));
 }
示例#22
0
 internal bool Edit(WorkoutLog entity)
 {
     return(dao.Edit(entity));
 }
示例#23
0
 internal bool Delete(WorkoutLog entity)
 {
     return(dao.Delete(entity));
 }
示例#24
0
 public bool Add(WorkoutLog workoutLog)
 {
     db.WorkoutLogs.Add(workoutLog);
     db.SaveChanges();
     return(true);
 }