Beispiel #1
0
        public ActionResult Create([Bind(Include = "Id,Name")] Meal meal)
        {
            if (ModelState.IsValid)
            {
                db.Meals.Add(meal);
                db.SaveChanges();
                return(View("Details", meal));
            }

            return(View(meal));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,Name,Portion,ServingSize,Calories,Carbs,Fat,Protein")] Food food)
        {
            if (ModelState.IsValid)
            {
                db.Foods.Add(food);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(food));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,Name,NoServings,Description,TotalCalories,TotalProteins,TotalFats,TotalCarbos,UserId")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                string currentUserId = User.Identity.GetUserId();
                User   currentUser   = db.Users.FirstOrDefault(x => x.Id == currentUserId);

                currentUser.Recipes.Add(recipe);
                db.SaveChanges();
                return(View("Details", recipe));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "Name", recipe.UserId);
            return(View(recipe));
        }
Beispiel #4
0
        public ActionResult AddFoodToMeal(ViewModelForMeal viewModel)//int selected, int id)
        {
            this.DropDownList();

            var  kontekst = new Kontekst();
            Food result   = kontekst.Foods
                            .FirstOrDefault(p => p.Id == viewModel.SelectedId);

            Recipe resultRecipe = new Recipe();

            resultRecipe = kontekst.Recipes
                           .Where(p => p.Id == viewModel.MealId)
                           .FirstOrDefault();

            resultRecipe.TotalCalories += result.Calories * resultRecipe.NoServings;
            resultRecipe.TotalCarbos   += Convert.ToInt32(result.Carbs * resultRecipe.NoServings);
            resultRecipe.TotalFats     += Convert.ToInt32(result.Fat * resultRecipe.NoServings);
            resultRecipe.TotalProteins += Convert.ToInt32(result.Protein * resultRecipe.NoServings);

            resultRecipe.Foods.Add(result);

            kontekst.SaveChanges();
            kontekst.Dispose();


            return(View("Details", resultRecipe));
        }
Beispiel #5
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }

                model.CaloriesPerDay = OptimalCaloriesCounter2(model);
                var user = new User {
                    UserName   = model.Email, Email = model.Email, Name = model.Name,
                    LastName   = model.LastName, Age = model.Age, CurrentWeight = model.CurrentWeight,
                    GoalWeight = model.GoalWeight, Height = model.Height, LevelOfActivity = model.SelectedLevel,
                    Gender     = model.Gender, DailyCalories = model.CaloriesPerDay
                };

                var progress = new Progress();
                progress.UserId            = user.Id;
                progress.UserDailyCalories = user.DailyCalories;
                progress.Weight            = user.CurrentWeight;

                Kontekst kontekst = new Kontekst();
                kontekst.Progress.Add(progress);
                kontekst.SaveChanges();
                kontekst.Dispose();

                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(View("UserHome", user));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
        public ActionResult Status(Status model)
        {
            using (Kontekst kontekst = new Kontekst())
            {
                Zamówienie noweZamówienie          = model.Zamówienie;
                Zamówienie dotychczasoweZamówienie = kontekst.Zamówienia.Find(noweZamówienie.Id);
                dotychczasoweZamówienie.StatusId = noweZamówienie.StatusId;
                kontekst.Entry(dotychczasoweZamówienie).State = EntityState.Modified;

                kontekst.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Usuń(long id)
        {
            using (Kontekst kontekst = new Kontekst())
            {
                DbSet <Zamówienie> zamówienia = kontekst.Zamówienia;
                Zamówienie         zamówienie = zamówienia.Find(id);

                if (zamówienie != null)
                {
                    zamówienia.Remove(zamówienie);
                    kontekst.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult PotwierdźOdbiór(long id)
        {
            using (Kontekst kontekst = new Kontekst())
            {
                Zamówienie zamówienie = kontekst.Zamówienia.Find(id);

                if (zamówienie != null)
                {
                    zamówienie.StatusId = 3;
                    kontekst.Entry(zamówienie).State = EntityState.Modified;

                    kontekst.SaveChanges();
                }
            }

            return(Index());
        }
Beispiel #9
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.CaloriesPerDay = OptimalCaloriesCounter(model);
                var user = new User {
                    UserName        = model.Email, Email = model.Email, Name = model.Name,
                    LastName        = model.LastName, Age = model.Age, CurrentWeight = model.CurrentWeight,
                    GoalWeight      = model.GoalWeight, Height = model.Height,
                    LevelOfActivity = model.SelectedLevel, Gender = model.Gender,
                    DailyCalories   = model.CaloriesPerDay
                };

                Progress progress = new Progress();
                progress.UserId            = user.Id;
                progress.UserDailyCalories = user.DailyCalories;
                progress.Weight            = user.CurrentWeight;

                Kontekst kontekst = new Kontekst();
                kontekst.Progress.Add(progress);
                kontekst.SaveChanges();
                kontekst.Dispose();

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(View("UserHome", user));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Dodaj(Dodaj model)
        {
            if (ModelState.IsValid)
            {
                Zamówienie zamówienie = model.Zamówienie;
                zamówienie.DataZłożenia = DateTime.Now;

                using (Kontekst kontekst = new Kontekst())
                {
                    kontekst.Zamówienia.Add(zamówienie);
                    kontekst.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            UzupełnijModelDodawania(model);

            return(View(model));
        }
Beispiel #11
0
        public ActionResult AddFoodToMeal(ViewModelForMeal viewModel)//int selected, int id)
        {
            this.DropDownList();

            var  kontekst = new Kontekst();
            Food result   = kontekst.Foods
                            .FirstOrDefault(p => p.Id == viewModel.SelectedId);

            viewModel.Foods.Add(result);

            Meal resultMeal = new Meal();

            resultMeal = kontekst.Meals
                         .Where(p => p.Id == viewModel.MealId)
                         .FirstOrDefault();

            resultMeal.Foods.Add(result);

            kontekst.SaveChanges();
            kontekst.Dispose();


            return(View("Details", resultMeal));
        }