public ActionResult EditCardio(CardioCreateViewModel viewModel)
 {
     viewModel.Cardio.Distance = Convert.ToDecimal(viewModel.DistanceString.Replace(".", ","));
     _unitOfWork.Cardios.EditCardio(viewModel.Cardio);
     _unitOfWork.Complete();
     return(RedirectToAction("TrainingBoard"));
 }
        public ActionResult CreateCardio()
        {
            var viewModel = new CardioCreateViewModel();

            viewModel.DistanceString = "0";
            viewModel.Cardio         = new Cardio();
            return(View(viewModel));
        }
        public ActionResult CreateCardio(CardioCreateViewModel viewModel)
        {
            viewModel.Cardio.UserId   = User.Identity.GetUserId();
            viewModel.Cardio.Distance = Convert.ToDecimal(viewModel.DistanceString.Replace(".", ","));
            _unitOfWork.Cardios.AddCardio(viewModel.Cardio);
            _unitOfWork.Complete();

            _unitOfWork.CardioAchievementsCheck(viewModel);

            _unitOfWork.Complete();

            return(RedirectToAction("TrainingBoard"));
        }
 public ActionResult Edit(int id, string type)
 {
     if (type == "cardio")
     {
         var model     = _unitOfWork.Cardios.GetCardio(id);
         var ViewModel = new CardioCreateViewModel();
         ViewModel.Cardio         = model;
         ViewModel.DistanceString = model.Distance.ToString().Replace(",", ".");
         return(View("EditCardio", ViewModel));
     }
     else
     {
         var model = _unitOfWork.Workouts.GetWorkout(id);
         return(View("EditWorkout", model));
     }
 }
Exemplo n.º 5
0
        public void CardioAchievementsCheck(CardioCreateViewModel cardioCreateViewModel)
        {
            var user             = Users.GetUser(cardioCreateViewModel.Cardio.UserId);
            var AchievementsList = Achievements.GetAllAchievement(cardioCreateViewModel.Cardio.UserId);
            var CardioList       = Cardios.GetAllCardios(cardioCreateViewModel.Cardio.UserId);

            var Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Pierwszy trenig cardio");

            if (CardioList.Any() && !Achievement.Acquired)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }

            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przebiegnij 5 km.");
            var test = CardioList.FirstOrDefault(c => c.Distance >= 5);

            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Bieganie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }

            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przebiegnij 10 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 10);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Bieganie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }

            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przebiegnij Półmaraton");
            test        = CardioList.FirstOrDefault(c => Convert.ToInt32(c.Distance * 10000) >= Convert.ToInt32(21.0975 * 10000));
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Bieganie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }

            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przebiegnij Maraton");
            test        = CardioList.FirstOrDefault(c => Convert.ToInt32(c.Distance * 10000) >= Convert.ToInt32(42.195 * 10000));
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Bieganie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }

            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "10 trenigów cardio");
            if (CardioList.Count() >= 10 && !Achievement.Acquired)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "20 trenigów cardio");
            if (CardioList.Count() >= 20 && !Achievement.Acquired)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "50 trenigów cardio");
            if (CardioList.Count() >= 50 && !Achievement.Acquired)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "100 trenigów cardio");
            if (CardioList.Count() >= 100 && !Achievement.Acquired)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przejedz rowerem 10 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 10);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Rower)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przejedz rowerem 20 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 20);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Rower)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przejedz rowerem 50 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 50);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Rower)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przejedz rowerem 100 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 100);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Rower)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przepłyń 1 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 1);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Pływanie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przepłyń 3 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 3);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Pływanie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przepłyń 5 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 5);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Pływanie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
            Achievement = AchievementsList.FirstOrDefault(a => a.Name == "Przepłyń 20 km.");
            test        = CardioList.FirstOrDefault(c => c.Distance >= 20);
            if (test != null && !Achievement.Acquired && cardioCreateViewModel.Cardio.CardioType == CardioType.Pływanie)
            {
                AcceptAchievement(Achievement, cardioCreateViewModel.Cardio.Date, user);
            }
        }