public IActionResult Create([Bind("UserName,UserFirstName,UserLastName,UserAge,UserEmail,UserGender,UserPassword")] DietUsers dietUsers, double UserWc, double UserWeight, double HeightMeter)
        {
            dietUsers.NewUser = true;
            try
            {
                if (ModelState.IsValid)
                {
                    double    WeightPound = 0;
                    double    HeightInch = 0;
                    UserClass newUser = new UserClass(dietUsers.UserName);
                    double    height, weight;

                    height     = HeightMeter;
                    HeightInch = height * 39.3701;


                    //if weight was already set in kg
                    WeightPound = UserWeight * 2.20462;
                    weight      = UserWeight;


                    newUser.NewUserConfig(dietUsers, UserWc, WeightPound, HeightInch, weight, height);

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(dietUsers));
            }
            catch (SqlException)
            {
                string action     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controller = this.ControllerContext.RouteData.Values["controller"].ToString();
                return(RedirectToAction("Error", new { controllerName = controller, actionName = action }));
            }
        }
Ejemplo n.º 2
0
        public IActionResult UpdateAccount([Bind("UserName,UserFirstName,UserLastName,UserAge,UserEmail,UserPassword")] DietUsers dietUsers)
        {
            try
            {
                string username = null;

                if (HttpContext.Session.GetString("LoggedIn") == null)
                {
                    return(RedirectToAction("Index"));
                }
                else

                {
                    username = HttpContext.Session.GetString("Username");
                    UserClass updateUser = new UserClass("Username");
                    var       dietuser   = db.DietUsers.Find(username);


                    dietuser.UserFirstName = dietUsers.UserFirstName;
                    dietuser.UserLastName  = dietUsers.UserLastName;
                    dietuser.UserEmail     = dietUsers.UserEmail;
                    dietuser.UserAge       = dietUsers.UserAge;
                    if (dietUsers.UserPassword != null)
                    {
                        MD5 md5Hash = MD5.Create();

                        string hash = UserClass.GetMd5Hash(md5Hash, dietUsers.UserPassword);
                        dietuser.UserPassword = hash;
                    }
                    db.Update(dietuser);
                    db.SaveChanges();



                    return(RedirectToAction("Dashboard"));
                }
            }
            catch (SqlException)
            {
                string action     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controller = this.ControllerContext.RouteData.Values["controller"].ToString();
                return(RedirectToAction("Error", new { controllerName = controller, actionName = action }));
            }
        }
        public async Task <IActionResult> Edit(string id, [Bind("UserName,UserFirstName,UserLastName,UserAge,UserEmail,UserGender,UserPassword,UserWeightCategory,ResetPasswordCode,NewUser,IsVeg,SetPicture")] DietUsers UPdietUsers)
        {
            try
            {
                if (id != UPdietUsers.UserName)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        var dietUser = _context.DietUsers.Where(x => x.UserName.ToLower() == id.ToLower()).AsNoTracking().FirstOrDefault();
                        UPdietUsers.Status = dietUser.Status;

                        _context.Update(UPdietUsers);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!DietUsersExists(UPdietUsers.UserName))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(UPdietUsers));
            }
            catch (SqlException)
            {
                string action     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controller = this.ControllerContext.RouteData.Values["controller"].ToString();
                return(RedirectToAction("Error", new { controllerName = controller, actionName = action }));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Signup([Bind("UserName,UserAge,UserPassword,UserFirstName,UserLastName,UserEmail,UserGender")] DietUsers dietUsers, double UserWc, string WeightMetric, string HeightMetric, double UserWeight, double HeightMeter = 0, double HeightFeet = 0, double HeightInches = 0)
        {
            double    WeightPound = 0;
            double    HeightInch = 0;
            UserClass newUser = new UserClass(dietUsers.UserName);
            double    height, weight;

            //Converting height to meters
            if (HeightMetric == "Feet")
            {
                height     = HeightFeet * 12;
                height    += HeightInches;
                height    *= 0.025;
                HeightInch = height;
            }
            else
            { //if height was already set in meter
                height     = HeightMeter;
                HeightInch = height * 39.3701;
            }
            if (WeightMetric == "kg")
            {
                //if weight was already set in kg
                WeightPound = UserWeight * 2.20462;
                weight      = UserWeight;
            }
            else
            {
                WeightPound = UserWeight;
                //converting weight into kg
                weight = UserWeight * 0.45;
            }
            newUser.NewUserConfig(dietUsers, UserWc, WeightPound, HeightInch, weight, height);

            //Start session for this user
            HttpContext.Session.SetString("LoggedIn", "True");
            HttpContext.Session.SetString("Username", dietUsers.UserName);
            //redirect to dashboard page
            return(RedirectToAction("Dashboard"));
        }