Ejemplo n.º 1
0
        public ActionResult Create(Rating rating)
        {
            if (ModelState.IsValid)
            {
                Profile profile = db.Profiles.Single(p => p.Login == User.Identity.Name);
                rating.Profile = profile;

                var ratings = db.Ratings.Where(r => r.RecipeID == rating.RecipeID && r.ProfileID == profile.ID);

                if (ratings.Count() > 0)
                {
                    ratings.First().Rate = rating.Rate;
                }
                else
                {
                    db.Ratings.Add(rating);
                }


                db.SaveChanges();
                return(RedirectToAction("Details", "Recipes", new { id = rating.RecipeID }));
            }

            ViewBag.ProfileID = new SelectList(db.Profiles, "ID", "Login", rating.ProfileID);
            ViewBag.RecipeID  = new SelectList(db.Recipes, "ID", "Name", rating.RecipeID);
            return(View(rating));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,Components,CategoryID,ProfileID,TypeID")] Recipe recipe)
        {
            HttpPostedFileBase file = Request.Files["fileWithPicture"];

            if (file != null && file.ContentLength > 0)
            {
                recipe.Picture = System.Guid.NewGuid().ToString();
                recipe.Picture = file.FileName;
                file.SaveAs(HttpContext.Server.MapPath("~/Pictures/") + recipe.Picture);
            }

            if (ModelState.IsValid)
            {
                Profile profile = db.Profiles.Single(p => p.Login == User.Identity.Name);
                recipe.Profile = profile;

                db.Recipes.Add(recipe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", recipe.CategoryID);
            ViewBag.ProfileID  = new SelectList(db.Profiles, "ID", "Login", recipe.ProfileID);
            ViewBag.TypeID     = new SelectList(db.Types, "ID", "Name", recipe.TypeID);
            return(View(recipe));
        }
Ejemplo n.º 3
0
        public RedirectToRouteResult Unlike([Bind(Include = "Id,RecipeID,ProfileID")] RecipeLike recipeLike, [Bind(Include = "RecipeID")] int recipeID)
        {
            int profileId = db.Profiles.Single(p => p.Login == User.Identity.Name).ID;

            db.RecipeLikes.Remove(db.RecipeLikes.Single(r => r.RecipeID == recipeID && r.ProfileID == profileId));
            db.SaveChanges();

            return(RedirectToAction("Details", "Recipes", new { id = recipeID }));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,Name")] Models.Type type)
        {
            if (ModelState.IsValid)
            {
                db.Types.Add(type);
                db.SaveChanges();
                return(RedirectToAction("Create", "Recipes"));
            }

            return(View(type));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ID,Login,FirstName,LastName,Age,IsMale")] Profile profile)
        {
            if (ModelState.IsValid)
            {
                db.Profiles.Add(profile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(profile));
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "ID,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Create", "Recipes"));
            }

            return(View(category));
        }
Ejemplo n.º 7
0
        public ActionResult Create(Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.Profile     = db.Profiles.Single(p => p.Login == User.Identity.Name);
                comment.CommentDate = DateTime.Now;
                db.Comments.Add(comment);
                db.SaveChanges();
                return(RedirectToAction("Details", "Recipes", new { id = comment.RecipeID }));
            }

            ViewBag.ProfileID = new SelectList(db.Profiles, "ID", "Login", comment.ProfileID);
            ViewBag.RecipeID  = new SelectList(db.Recipes, "ID", "Name", comment.RecipeID);
            return(View(comment));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Register(RegisterViewModel model, string FirstName, string LastName, int Age, bool IsMale)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

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

                    EBookContext db = new EBookContext();

                    Profile profile = new Profile()
                    {
                        Login     = model.Email,
                        FirstName = FirstName,
                        LastName  = LastName,
                        Age       = Age,
                        IsMale    = IsMale
                    };

                    db.Profiles.Add(profile);
                    db.SaveChanges();

                    // For more information on how to enable account confirmation and password reset please visit http://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));
        }