Exemple #1
0
        public ActionResult Create(Challenge model, int GroupId)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (FitAppContext db = new FitAppContext())
                {
                    var       group     = db.Groups.Where(m => m.Id == GroupId).FirstOrDefault();
                    Challenge challenge = new Challenge();
                    challenge.Subject = model.Subject;
                    challenge.EndDate = model.EndDate;
                    challenge.GroupId = GroupId;

                    group.Challenges.Add(challenge);
                    db.SaveChanges();
                }
                return(RedirectToAction("List", "Challenge", new { Id = GroupId }));
            }
            else
            {
                message = "Uzupełnij dane";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Exemple #2
0
        public ActionResult ForgotPassword(string Email)
        {
            bool   status  = false;
            string message = "";

            using (FitAppContext db = new FitAppContext())
            {
                var account = db.Users.Where(m => m.Email == Email).FirstOrDefault();
                if (account != null)
                {
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                    message = "Check your email for verification link";
                }
                else
                {
                    message = User.Identity.Name;
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Exemple #3
0
 public ActionResult Edit(Exercise model)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var exercise    = db.Exercises.Where(m => m.Id == model.Id).FirstOrDefault();
         var caloriesNow = exercise.BurnedCalories;
         var trainingId  = exercise.TrainingId;
         if (exercise != null)
         {
             ViewBag.ExerciseName    = exercise.ExerciseName;
             ViewBag.VideoLink       = exercise.VideoLink;
             ViewBag.BurnedCalories  = exercise.BurnedCalories;
             ViewBag.Description     = exercise.Description;
             exercise.ExerciseName   = model.ExerciseName;
             exercise.VideoLink      = model.VideoLink;
             exercise.BurnedCalories = model.BurnedCalories;
             exercise.Description    = model.Description;
             var diff     = model.BurnedCalories - caloriesNow;;
             var training = db.Trainings.Where(m => m.Id == trainingId).FirstOrDefault();
             training.BurnedCalories += diff;
             db.SaveChanges();
         }
         else
         {
             return(View(model));
         }
         return(RedirectToAction("List", "Exercise", new { Id = trainingId }));
     }
 }
Exemple #4
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (FitAppContext db = new FitAppContext())
                {
                    var account = db.Users.Where(m => m.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (account != null)
                    {
                        account.Password          = Crypto.Hash(model.NewPassword);
                        account.ResetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "Password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something went wrong";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Exemple #5
0
        public ActionResult Create(Group model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (FitAppContext db = new FitAppContext())
                {
                    var user = db.Users.Where(m => m.Login == User.Identity.Name).FirstOrDefault();
                    if (user != null)
                    {
                        Group group = new Group();
                        group.AdminId      = user.Id;
                        group.GroupName    = model.GroupName;
                        group.GroupType    = model.GroupType;
                        group.MembersCount = 1;

                        user.Groups.Add(group);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(RedirectToAction("Login", "User"));
                    }
                }
                return(RedirectToAction("Mine", "Group"));
            }
            else
            {
                message = "Uzupełnij dane";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Exemple #6
0
        public ActionResult SetDate(Meal model)
        {
            using (FitAppContext db = new FitAppContext())
            {
                var user = db.Users.Where(u => u.Login.Equals(User.Identity.Name)).FirstOrDefault();
                var meal = db.Meals.Where(m => m.Id == model.Id).FirstOrDefault();
                if (meal != null)
                {
                    meal.MealDate = model.MealDate;
                    meal.MealTime = model.MealTime;
                    meal.UserId   = user.Id;
                    db.Meals.Add(meal);

                    var foods = db.Foods.Where(m => m.MealId == model.Id).ToList();
                    foreach (var item in foods)
                    {
                        item.MealId = meal.Id;
                        db.Foods.Add(item);
                    }

                    db.SaveChanges();

                    return(RedirectToAction("List", "Meal"));
                }
                else
                {
                    return(RedirectToAction("Add", "Meal"));
                }
            }
        }
Exemple #7
0
 public ActionResult Add(Training model)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var user = db.Users.Where(u => u.Login.Equals(User.Identity.Name)).FirstOrDefault();
         if (user != null)
         {
             if (ModelState.IsValid)
             {
                 model.UserId         = user.Id;
                 model.BurnedCalories = 0;
                 model.ExerciseCount  = 0;
                 db.Trainings.Add(model);
                 db.SaveChanges();
             }
             else
             {
                 return(View(model));
             }
             return(RedirectToAction("List", "Training"));
         }
         else
         {
             return(RedirectToAction("Login", "User"));
         }
     }
 }
Exemple #8
0
        public ActionResult Add(Food model)
        {
            using (FitAppContext db = new FitAppContext())
            {
                var user = db.Users.Where(u => u.Login.Equals(User.Identity.Name)).FirstOrDefault();

                if (user != null)
                {
                    if (user.UserType == "admin")
                    {
                        if (ModelState.IsValid)
                        {
                            model.MealId = 1;
                            db.Foods.Add(model);
                            db.SaveChanges();
                        }
                        else
                        {
                            return(View(model));
                        }
                        return(RedirectToAction("Composition", "Meal", new { Id = 1 }));
                    }
                    else
                    {
                        return(RedirectToAction("Permission", "Error"));
                    }
                }
                else
                {
                    return(RedirectToAction("Login", "User"));
                }
            }
        }
Exemple #9
0
        public IHttpActionResult Done([FromBody] int TaskId)
        {
            var task = db.Tasks.Where(m => m.Id == TaskId).FirstOrDefault();
            var user = db.Users.Where(m => m.Login == User.Identity.Name).FirstOrDefault();

            if (!user.TasksDone.Contains(task))
            {
                user.TasksDone.Add(task);
                if (!task.UsersWhoDid.Contains(user))
                {
                    task.UsersWhoDid.Add(user);
                }
                else
                {
                    return(BadRequest("Zadanie jest zrealizowane"));
                }
            }
            else
            {
                return(BadRequest("Zadanie jest zrealizowane"));
            }
            db.SaveChanges();

            return(Ok());
        }
Exemple #10
0
        public ActionResult Create(Task model, int Id)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (FitAppContext db = new FitAppContext())
                {
                    Task task = new Task();
                    task.ChallengeId     = Id;
                    task.Description     = model.Description;
                    task.RealizationTime = model.RealizationTime;
                    db.Tasks.Add(task);
                    db.SaveChanges();
                }

                return(RedirectToAction("List", "Task", new { Id = Id }));
            }
            else
            {
                message = "Uzupełnij dane";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Exemple #11
0
        public ActionResult Add(Meal model)
        {
            using (FitAppContext db = new FitAppContext())
            {
                var user = db.Users.Where(u => u.Login.Equals(User.Identity.Name)).FirstOrDefault();

                if (user != null)
                {
                    if (ModelState.IsValid)
                    {
                        model.UserId = user.Id;
                        db.Meals.Add(model);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(View(model));
                    }
                    return(RedirectToAction("List", "Meal"));
                }
                else
                {
                    return(RedirectToAction("Login", "User"));
                }
            }
        }
Exemple #12
0
        public ActionResult Edit(Measurment model)
        {
            var message = "";

            using (FitAppContext db = new FitAppContext())
            {
                var measurment = db.Measurments.Where(m => m.Id == model.Id).FirstOrDefault();
                if (measurment != null)
                {
                    measurment.MeasurmentDate   = model.MeasurmentDate;
                    measurment.Weight           = model.Weight;
                    measurment.Height           = model.Height;
                    measurment.BicepsCircuit    = model.BicepsCircuit;
                    measurment.ThighCircuit     = model.ThighCircuit;
                    measurment.WeistCircuit     = model.WeistCircuit;
                    measurment.ChestCircuit     = model.ChestCircuit;
                    measurment.HipsCircuit      = model.HipsCircuit;
                    measurment.ShouldersCircuit = model.ShouldersCircuit;
                    measurment.ActivityLevel    = model.ActivityLevel;
                    db.SaveChanges();
                    message = "Dane zostały zaktualizowane";
                }
                else
                {
                    message = "Nie udało się zaktualizować danych";
                    return(View(model));
                }
            }
            ViewBag.Message = message;
            return(RedirectToAction("History", "Measurment"));
        }
Exemple #13
0
 public ActionResult Delete(int Id)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var measurment = db.Measurments.Where(m => m.Id == Id).FirstOrDefault();
         db.Measurments.Remove(measurment);
         db.SaveChanges();
         return(RedirectToAction("History", "Measurment"));
     }
 }
 public ActionResult Delete(int Id)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var exercise = db.ExerciseAdmins.Where(m => m.Id == Id).FirstOrDefault();
         db.ExerciseAdmins.Remove(exercise);
         db.SaveChanges();
         return(RedirectToAction("List", "ExerciseAdmin"));
     }
 }
Exemple #15
0
 public ActionResult DeleteMeal(int Id)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var meal = db.Meals.Where(u => u.Id.Equals(Id)).FirstOrDefault();
         db.Meals.Remove(meal);
         db.SaveChanges();
         return(RedirectToAction("List", "Meal"));
     }
 }
Exemple #16
0
        public ActionResult Data(User model)
        {
            var message = "";

            using (FitAppContext db = new FitAppContext())
            {
                var user = db.Users.Where(m => m.Login == User.Identity.Name).FirstOrDefault();
                if (user != null)
                {
                    ViewBag.UserName     = model.Name;
                    ViewBag.UserSurname  = model.Surname;
                    ViewBag.UserBirthDay = model.BirthDay.ToShortDateString();
                    ViewBag.UserEmail    = model.Email;
                    ViewBag.UserSex      = model.Sex;
                    if (user.IsEmailVerified == true)
                    {
                        user.Name     = model.Name;
                        user.Surname  = model.Surname;
                        user.BirthDay = model.BirthDay;
                        user.Sex      = model.Sex;
                        if (model.Email != user.Email)
                        {
                            user.Email           = model.Email;
                            user.IsEmailVerified = false;
                            var code = Guid.NewGuid();
                            user.ActivationCode = code;
                            SendVerificationLinkEmail(model.Email, code.ToString());
                        }


                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "Dane zostały zaktualizowane";
                    }
                    else
                    {
                        ViewBag.UserName     = user.Name;
                        ViewBag.UserSurname  = user.Surname;
                        ViewBag.UserBirthDay = user.BirthDay.ToShortDateString();
                        ViewBag.UserEmail    = user.Email;
                        ViewBag.UserSex      = user.Sex;
                        message         = "Potwierdź email w celu zmiany danych";
                        ViewBag.Message = message;
                    }
                }
                else
                {
                    message = "Coś poszło nie tak";
                }
            }

            ViewBag.Message = message;
            return(View());
        }
Exemple #17
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                #region Email/Login existance
                var doExistEmail = IsEmailExists(user.Email);
                var doExistLogin = DoLoginExists(user.Login);
                if (doExistLogin)
                {
                    ModelState.AddModelError("LoginExists", "Podany login już istnieje");
                    return(View(user));
                }
                if (doExistEmail)
                {
                    ModelState.AddModelError("EmailExists", "Podany email już istnieje");
                    return(View(user));
                }

                #endregion
                #region Generate Activation COde
                user.ActivationCode = Guid.NewGuid();
                #endregion
                #region Password hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion
                user.IsEmailVerified = false;

                #region Save to Dataase
                using (FitAppContext db = new FitAppContext())
                {
                    db.Users.Add(user);
                    db.SaveChanges();

                    SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString());
                    message = "Rejestracja udana. Aktywuj swoje konto";
                    Status  = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }
            ViewBag.Message = message;
            ViewBag.Status  = Status;

            return(View(user));
        }
 public ActionResult Add(Exercise model)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var exercise = new ExerciseAdmin();
         exercise.ExerciseName   = model.ExerciseName;
         exercise.VideoLink      = model.VideoLink;
         exercise.BurnedCalories = model.BurnedCalories;
         exercise.Description    = model.Description;
         db.ExerciseAdmins.Add(exercise);
         db.SaveChanges();
     }
     return(RedirectToAction("List", "ExerciseAdmin"));
 }
Exemple #19
0
 public ActionResult Delete(int Id)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var exercise   = db.Exercises.Where(m => m.Id == Id).FirstOrDefault();
         var trainingId = exercise.TrainingId;
         var training   = db.Trainings.Where(m => m.Id == trainingId).FirstOrDefault();
         training.BurnedCalories -= exercise.BurnedCalories;
         training.ExerciseCount  -= 1;
         db.Exercises.Remove(exercise);
         db.SaveChanges();
         return(RedirectToAction("List", "Exercise", new { Id = trainingId }));
     }
 }
Exemple #20
0
        public ActionResult Delete(int Id)
        {
            using (FitAppContext db = new FitAppContext())
            {
                var group      = db.Groups.Where(m => m.Id == Id).FirstOrDefault();
                var challenges = group.Challenges.ToList();

                foreach (var ch in challenges)
                {
                    var tasks = ch.Tasks.ToList();
                    foreach (var t in tasks)
                    {
                        foreach (var u in t.UsersWhoDid)
                        {
                            TaskRepository.TaskEdit(t, u.Id, ch.Subject);
                        }
                    }
                }

                db.Groups.Remove(group);
                db.SaveChanges();

                return(RedirectToAction("Mine", "Group"));
            }

            /*
             * using (FitAppContext db = new FitAppContext())
             * {
             *  var challenge = db.Challenges.Where(m => m.Id == Id).FirstOrDefault();
             *  var groupId = challenge.GroupId;
             *
             *  var tasks = challenge.Tasks.ToList();
             *
             *  foreach (var t in tasks)
             *  {
             *      foreach (var u in t.UsersWhoDid)
             *      {
             *          TaskRepository.TaskEdit(t, u.Id, challenge.Subject);
             *      }
             *
             *  }
             *
             *  db.Challenges.Remove(challenge);
             *  db.SaveChanges();
             *
             *  return RedirectToAction("List", "Challenge", new { Id = groupId });
             * }
             */
        }
Exemple #21
0
        public ActionResult Delete(int Id)
        {
            using (FitAppContext db = new FitAppContext())
            {
                var tr = db.Trainings.Where(u => u.Id.Equals(Id)).FirstOrDefault();
                if (tr.ExerciseCount > 0)
                {
                    var exercises = db.Exercises.Where(u => u.TrainingId == tr.Id).FirstOrDefault();
                    db.Exercises.Remove(exercises);
                }

                db.Trainings.Remove(tr);
                db.SaveChanges();
                return(RedirectToAction("List", "Training"));
            }
        }
Exemple #22
0
 public ActionResult Edit(Task model)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var task = db.Tasks.Where(m => m.Id == model.Id).FirstOrDefault();
         if (task != null)
         {
             ViewBag.Description     = model.Description;
             ViewBag.RealizationTime = model.RealizationTime.ToShortDateString();
             task.Description        = model.Description;
             task.RealizationTime    = model.RealizationTime;
         }
         db.SaveChanges();
     }
     ViewBag.Message = "Dane zostały uaktualnione";
     return(View());
 }
Exemple #23
0
 public ActionResult Add(Exercise model, int TrainingId)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var      training = db.Trainings.Where(m => m.Id == TrainingId).FirstOrDefault();
         Exercise exercise = new Exercise();
         exercise.ExerciseName    = model.ExerciseName;
         exercise.VideoLink       = model.VideoLink;
         exercise.BurnedCalories  = model.BurnedCalories;
         exercise.Description     = model.Description;
         exercise.TrainingId      = TrainingId;
         training.BurnedCalories += model.BurnedCalories;
         training.ExerciseCount  += 1;
         training.Exercises.Add(exercise);
         db.SaveChanges();
     }
     return(RedirectToAction("List", "Exercise", new { Id = TrainingId }));
 }
Exemple #24
0
 public ActionResult Unenrol(int Id)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var group = db.Groups.Where(m => m.Id == Id).FirstOrDefault();
         if (group != null)
         {
             var user = db.Users.Where(m => m.Login == User.Identity.Name).FirstOrDefault();
             group.Users.Remove(user);
             group.MembersCount--;
             db.SaveChanges();
             return(RedirectToAction("Mine", "Group"));
         }
         else
         {
             return(RedirectToAction("Mine", "Group"));
         }
     }
 }
Exemple #25
0
 public ActionResult ExampleAdd(int id, int idx)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var      training = db.Trainings.Where(m => m.Id == idx).FirstOrDefault();
         var      exAdm    = db.ExerciseAdmins.Where(m => m.Id == id).FirstOrDefault();
         Exercise exercise = new Exercise();
         exercise.ExerciseName    = exAdm.ExerciseName;
         exercise.VideoLink       = exAdm.VideoLink;
         exercise.BurnedCalories  = exAdm.BurnedCalories;
         exercise.Description     = exAdm.Description;
         exercise.TrainingId      = training.Id;
         training.BurnedCalories += exAdm.BurnedCalories;
         training.ExerciseCount  += 1;
         training.Exercises.Add(exercise);
         db.SaveChanges();
     }
     return(RedirectToAction("List", "Exercise", new { Id = idx }));
 }
Exemple #26
0
 public ActionResult Edit(Training model)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var tr = db.Trainings.Where(m => m.Id == model.Id).FirstOrDefault();
         if (tr != null)
         {
             ViewBag.TrainingName = tr.TrainingName;
             ViewBag.TrainingTime = tr.TrainingTime.ToShortDateString();
             tr.TrainingName      = model.TrainingName;
             tr.TrainingTime      = model.TrainingTime;
             db.SaveChanges();
         }
         else
         {
             return(View(model));
         }
     }
     return(RedirectToAction("List", "Training"));
 }
Exemple #27
0
        public ActionResult Edit(Group model)
        {
            using (FitAppContext db = new FitAppContext())
            {
                var group = db.Groups.Where(m => m.Id == model.Id).FirstOrDefault();
                if (group != null)
                {
                    group.GroupName = model.GroupName;
                    group.GroupType = model.GroupType;

                    db.SaveChanges();

                    return(RedirectToAction("Mine", "Group"));
                }
                else
                {
                    return(RedirectToAction("Create", "Group"));
                }
            }
        }
Exemple #28
0
        public ActionResult Select(int Id)
        {
            int mId = (int)TempData["MealId"];

            TempData.Keep("MealId");
            using (FitAppContext db = new FitAppContext())
            {
                var food = db.Foods.Where(f => f.Id.Equals(Id)).FirstOrDefault();
                food.MealId = mId;
                db.Foods.Add(food);

                var meal = db.Meals.Where(m => m.Id.Equals(mId)).FirstOrDefault();
                meal.MealCalories += food.Calories;
                meal.MealCarbs    += food.Carbs;
                meal.MealFat      += food.Fat;
                meal.MealProteins += food.Proteins;

                db.SaveChanges();
                return(Redirect(Request.UrlReferrer.PathAndQuery));
            }
        }
Exemple #29
0
        public ActionResult Block(int UserId)
        {
            using (FitAppContext db = new FitAppContext())
            {
                try
                {
                    var user    = db.Users.Where(m => m.Id == UserId).FirstOrDefault();
                    var groupId = int.Parse(Request.UrlReferrer.Segments.Last());

                    var group = db.Groups.Where(m => m.Id == groupId).FirstOrDefault();
                    group.Users.Remove(user);
                    group.MembersCount--;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                }

                return(RedirectToAction("Mine", "Group"));
            }
        }
Exemple #30
0
 public ActionResult Enrol(int Id)
 {
     using (FitAppContext db = new FitAppContext())
     {
         var group = db.Groups.Where(m => m.Id == Id).FirstOrDefault();
         if (group != null)
         {
             var user = db.Users.Where(m => m.Login == User.Identity.Name).FirstOrDefault();
             group.Users.Add(user);
             group.MembersCount++;
             user.Groups.Add(group);
             db.SaveChanges();
             ViewBag.Message = "Udalo sie dodac";
             return(RedirectToAction("Mine", "Group"));
         }
         else
         {
             ViewBag.Message = "Coś poszło nie tak";
             return(RedirectToAction("List", "Group"));
         }
     }
 }