Ejemplo n.º 1
0
        public IActionResult submittingAddtional(string Activity_Lev, string Preferences, bool IsAllergic, string Allergies, bool IsVeg)
        {
            var       username   = HttpContext.Session.GetString("Username");
            Allergies addAllergy = new Allergies();

            addAllergy.RecordId      = Guid.NewGuid();
            addAllergy.UserName      = username;
            addAllergy.IsAllergic    = IsAllergic;
            addAllergy.AllergiesList = Allergies;
            //allergyList
            db.Add(addAllergy);

            Preferences AddPreferences = new Preferences();

            AddPreferences.RecordId        = Guid.NewGuid();
            AddPreferences.Username        = username;
            AddPreferences.PreferencesList = Preferences;
            db.Add(AddPreferences);

            double?TDEE = 0;
            var    user = db.ProgressTracker.Where(x => x.UserName.ToLower() == username.ToLower()).FirstOrDefault();

            user.ActivityLevel = Activity_Lev;

            switch (Activity_Lev)
            {
            case "sedentary": TDEE = user.Bmr * 1.2; break;

            case "lightly": TDEE = user.Bmr * 1.375; break;

            case "mild": TDEE = user.Bmr * 1.55; break;

            case "very": TDEE = user.Bmr * 1.725; break;

            case "extra": TDEE = user.Bmr * 1.9; break;
            }

            user.Tdee = (double)TDEE;
            db.Update(user);
            var dietuser = db.DietUsers.Find(username);

            dietuser.NewUser = false;
            db.Update(dietuser);

            db.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }
        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 }));
            }
        }
        public async Task <IActionResult> Suspend(string id, string Status)
        {
            try
            {
                if (Status == "Suspend")
                {
                    Status = "Suspended";
                }

                if (id == null)
                {
                    return(NotFound());
                }

                var Admins = await _context.AdminsTable.FindAsync(id);

                if (Admins == null)
                {
                    return(NotFound());
                }

                else
                {
                    Admins.Status = Status;
                }
                _context.Update(Admins);
                await _context.SaveChangesAsync();


                return(RedirectToAction(nameof(Index)));
            }
            catch (SqlException)
            {
                string action     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controller = this.ControllerContext.RouteData.Values["controller"].ToString();
                return(RedirectToAction("Error", "Admin", new { controllerName = controller, actionName = action }));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,servqty,serv,group,food")] FoodDb foodDb)
        {
            try
            {
                if (id != foodDb.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(foodDb);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!FoodDbExists(foodDb.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(foodDb));
            }
            catch (SqlException)
            {
                string action     = this.ControllerContext.RouteData.Values["action"].ToString();
                string controller = this.ControllerContext.RouteData.Values["controller"].ToString();
                return(RedirectToAction("Error", "Admin", new { controllerName = controller, actionName = action }));
            }
        }