public ActionResult Create([Bind(Include = "Id,Title")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                db.Ingredients.Add(ingredient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ingredient));
        }
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,EmailAddress")] UserProfile userProfile)
        {
            if (ModelState.IsValid)
            {
                db.UserProfiles.Add(userProfile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userProfile));
        }
        public ActionResult Create([Bind(Include = "Id,Amount,Name,Unit,RecipeTitle,RecipeUrl")] ListIngredient listIngredient)
        {
            if (ModelState.IsValid)
            {
                listIngredient.UserProfileId = User.Identity.GetUserId();

                db.ListIngredients.Add(listIngredient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(listIngredient));
        }
Exemple #4
0
        public ActionResult Create(IngredientVM viewModel)
        {
            var userId = User.Identity.GetUserId();



            if (ModelState.IsValid)
            {
                var ingredient = db.Ingredients.SingleOrDefault(i => i.Title == viewModel.Title);
                if (ingredient == null)
                {
                    ingredient = new Ingredient
                    {
                        Title = viewModel.Title.ToLower(),
                    };
                }

                var fridgeIngredient = db.FridgeIngredients.SingleOrDefault(i => i.IngredientId == ingredient.Id && i.UserProfileId == userId && i.MeasurementId == viewModel.MeasurementId);
                if (fridgeIngredient == null)
                {
                    fridgeIngredient = new FridgeIngredient
                    {
                        Ingredient    = ingredient,
                        Amount        = viewModel.Amount,
                        MeasurementId = viewModel.MeasurementId,
                        UserProfileId = User.Identity.GetUserId(),
                    };

                    db.FridgeIngredients.Add(fridgeIngredient);
                }
                else
                {
                    fridgeIngredient.Amount         += viewModel.Amount;
                    db.Entry(fridgeIngredient).State = EntityState.Modified;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IngredientId  = new SelectList(db.Ingredients, "Id", "Title");
            ViewBag.MeasurementId = new SelectList(db.Measurements, "Id", "unit", viewModel.MeasurementId);
            return(View(viewModel));
        }
Exemple #5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var userProfile = new UserProfile
                    {
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        EmailAddress = model.EmailAddress,
                        UserId       = user.Id
                    };
                    using (var db = new EatInDBEntities())
                    {
                        db.UserProfiles.Add(userProfile);
                        db.SaveChanges();
                    }
                    EmailUtility.SendConfirmation(model.EmailAddress, "Welcome to eat smrt! You are now a registered user.");
                    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(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }