Ejemplo n.º 1
0
        public ActionResult UpdatePlan(int sportId, int lvl)
        {
            var model = (SportNutritionPlanModel)Session["UserData"];

            var generatePlan   = new GeneratePlan();
            var user           = new Users();
            var sportPlan      = new SportPlan();
            var statisticLogic = new Statistics();

            var loggedInData = user.GetUser(model.User.Id);

            var userData = new SportNutritionPlanModel
            {
                SportPlan     = sportPlan.PutSportDone(model.User.Id, sportId).Sport,
                NutritionPlan = generatePlan.GenerateNutritionPlan(loggedInData),
                User          = loggedInData
            };

            if (userData.SportPlan.Count <= 0)
            {
                //Textas kazkoks kai tuscia
            }
            Session["UserData"] = userData;
            var statisticsModel = statisticLogic.GetStatisticsById(userData.User.Id);

            statisticsModel.CurrentLvl = lvl;
            statisticsModel.DoneCount += 1;
            statisticsModel            = statisticLogic.PutStatistics(statisticsModel);

            return(View("Plan", userData));
        }
Ejemplo n.º 2
0
        public ActionResult Login(UserModel userModel)
        {
            var generatePlan = new GeneratePlan();
            var user         = new Users();
            var sportPlan    = new SportPlan();

            var loggedInData = user.UserLogin(userModel.UserName, userModel.Password);

            if (loggedInData != null)
            {
                var userData = new SportNutritionPlanModel
                {
                    SportPlan     = generatePlan.GenerateSportPlan(loggedInData),
                    NutritionPlan = generatePlan.GenerateNutritionPlan(loggedInData),
                    User          = loggedInData
                };

                var allDone   = sportPlan.GetAllSportPlansById(userData.User.Id);
                var createNew = true;
                foreach (var item in allDone.Sport)
                {
                    if (item.Done == 0)
                    {
                        createNew = false;
                    }
                }
                if (createNew)
                {
                    sportPlan.DeleteSportPlan(userData.User.Id);
                    userData.SportPlan = sportPlan.PostSportPlan(loggedInData.Id, 1).Sport;
                }

                if (userData.SportPlan.Count <= 0)
                {
                    //Textas kazkoks kai tuscia
                }

                ViewBag.Id = userData.User.Id;

                Session["UserData"] = userData;

                if (userData.User.RoleId == 2)
                {
                    return(RedirectToAction("AdminPanel", "Administration"));
                }
                return(RedirectToAction("Plan", "Sport"));
            }

            TempData["badPassword"] = "******";
            return(RedirectToAction("Login", "Authentication"));
        }
Ejemplo n.º 3
0
        public ActionResult UserProfileSave(UserProfileViewModel model)
        {
            var user         = new Users();
            var generatePlan = new GeneratePlan();

            var pass     = model.Password;
            var newModel = new UserModel
            {
                Id         = model.Id,
                RoleId     = model.RoleId,
                Name       = model.Name,
                Surname    = model.Surname,
                Address    = model.Address,
                Email      = model.Email,
                UserName   = model.UserName,
                Age        = model.Age,
                Weight     = model.Weight,
                Height     = model.Height,
                Difficulty = model.Difficulty
            };

            newModel.Password = null;

            if (user.PutUser(model.Id, newModel) != null)
            {
                newModel.Password = pass;

                var sportPlan = new SportPlan();
                var sports    = sportPlan.GetSportPlanById(newModel.Id);

                var level = 1;
                foreach (var item in sports.Sport)
                {
                    level = item.Level;
                }
                sportPlan.DeleteSportPlan(newModel.Id);
                var sport = sportPlan.PostSportPlan(newModel.Id, level);

                var userData = new SportNutritionPlanModel
                {
                    SportPlan     = sport.Sport,
                    NutritionPlan = generatePlan.GenerateNutritionPlan(newModel),
                    User          = newModel
                };

                return(View("../Sport/Plan", userData));
            }
            return(RedirectToAction("UserProfile", "Administration", model.Id));
        }