Beispiel #1
0
        public ActionResult Details(CategoriesListData model, int pageNumber = 1)
        {
            string name = User.Identity.Name;

            model.AllCategory = new CategoryManager().GetAllCategory();

            Recipes recipe = db.Recipes.Find(model.RecipesDB.ID);

            db.Recipes.Remove(recipe);
            try
            {
                System.IO.File.Delete(Path.Combine(Server.MapPath("~"), "Upload\\Images", recipe.PictureUrl));
            }
            catch { }
            db.SaveChanges();

            List <Comments> comments = new CommentManager().GetRecipeCommentsList(model.RecipesDB.ID);

            foreach (Comments comment in comments)
            {
                db.Comments.Remove(comment);
            }

            db.SaveChanges();
            model.Recipes = new RecipeManager().GetUserRecipes(name, pageNumber);
            return(View(model));
        }
Beispiel #2
0
 // GET: Comments/Create
 public ActionResult Create(int recipeId)
 {
     var model = new CategoriesListData();
     model.SelectedRecipe = new RecipeManager().GetRecipeHeaderData(recipeId);
     model.CommentsDB = new Comments();
     return PartialView(model);
 }
Beispiel #3
0
        public ActionResult Details(CategoriesListData model, int pageNumber = 1)
        {
            CategoryManager manager = new CategoryManager();

            model.AllCategory = manager.GetAllCategory();

            Recipes recipe = db.Recipes.Find(model.RecipesDB.ID);

            db.Recipes.Remove(recipe);
            System.IO.File.Delete(Path.Combine(Server.MapPath("~"), "Upload\\Images", recipe.PictureUrl));
            db.SaveChanges();

            List <Comments> comments = new CommentManager().GetRecipeCommentsList(model.RecipesDB.ID);

            foreach (Comments comment in comments)
            {
                db.Comments.Remove(comment);
            }
            db.SaveChanges();

            Categories category = db.Categories.Find(model.SelectedCategory.ID);

            model.Recipes          = manager.GetRecipesInCategory(category.FriendlyUrl, pageNumber);
            model.SelectedCategory = model.AllCategory.FirstOrDefault(c => c.FriendlyUrl == category.FriendlyUrl);
            return(View(model));
        }
Beispiel #4
0
 public ActionResult ListComments(int recipeId, int pageNumber = 1)
 {
     var model = new CategoriesListData();
     model.Comments = new CommentManager().GetRecipeComments(recipeId, pageNumber);
     model.SelectedRecipe = new RecipeManager().GetRecipeHeaderData(recipeId);
     return PartialView(model);
 }
Beispiel #5
0
        // GET: Recipes/Create
        public ActionResult Create()
        {
            var model = new CategoriesListData();

            model.AllCategory = new CategoryManager().GetAllCategory();
            model.RecipesDB   = new Recipes();
            return(View(model));
        }
Beispiel #6
0
        public ActionResult Index(string sortBy, int pageNumber = 1)
        {
            var model = new CategoriesListData();

            model.AllCategory = new CategoryManager().GetAllCategory();
            model.Recipes     = new RecipeManager().GetAllRecipeHeaderData(sortBy, pageNumber);
            return(View(model));
        }
Beispiel #7
0
        // GET: Recipes/Details/5
        public ActionResult Details(string sortBy, int pageNumber = 1)
        {
            string name  = User.Identity.Name;
            var    model = new CategoriesListData();

            model.AllCategory = new CategoryManager().GetAllCategory();
            model.Recipes     = new RecipeManager().GetUserRecipes(sortBy, name, pageNumber);
            return(View(model));
        }
Beispiel #8
0
        public ActionResult Search(string title, int pageNumber = 1)
        {
            var model = new CategoriesListData();

            model.AllCategory = new CategoryManager().GetAllCategory();
            model.Recipes     = new RecipeManager().GetAllRecipes()
                                .Where(r => r.Title.ToLower().Contains(title.ToLower()))
                                .ToPagedList(pageNumber, 8);
            return(View(model));
        }
Beispiel #9
0
 public ActionResult Edit(CategoriesListData model)
 {
     if (ModelState.IsValid)
     {
         model.CommentsDB.CreatedDate = Convert.ToDateTime(DateTime.Now.ToString(new CultureInfo("hu-HU")));
         db.Entry(model.CommentsDB).State = EntityState.Modified;
         db.SaveChanges();
     }
     return PartialView(model);
 }
Beispiel #10
0
        // GET: Categories/Details/5
        public ActionResult Details(string friendlyUrl, string sortBy, int pageNumber = 1)
        {
            var manager = new CategoryManager();
            var model   = new CategoriesListData
            {
                Recipes     = manager.GetRecipesInCategory(friendlyUrl, sortBy, pageNumber),
                AllCategory = manager.GetAllCategory()
            };

            model.SelectedCategory = model.AllCategory.FirstOrDefault(c => c.FriendlyUrl == friendlyUrl);
            return(View(model));
        }
Beispiel #11
0
 public ActionResult Comments(CategoriesListData model, int pageNumber = 1)
 {
     model.SelectedRecipe = new RecipeManager().GetRecipeHeaderData(model.CommentsDB.RecipesId);
     Comments comment = db.Comments.Find(model.CommentsDB.Id);
     if(comment != null)
     {
         db.Comments.Remove(comment);
         db.SaveChanges();
     }
     model.Comments = new CommentManager().GetRecipeComments(model.SelectedRecipe.ID, pageNumber);
     return View(model);
 }
Beispiel #12
0
 public ActionResult Edit(int? commentId)
 {
     if (commentId == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Comments comment = db.Comments.Find(commentId);
     var model = new CategoriesListData();
     model.CommentsDB = comment;
     if (comment == null)
     {
         return HttpNotFound();
     }
     return PartialView(model);
 }
Beispiel #13
0
        // GET: Recipes/Edit/5
        public ActionResult Edit(int?recipeId)
        {
            if (recipeId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recipes recipes = db.Recipes.Find(recipeId);
            var     model   = new CategoriesListData();

            model.AllCategory = new CategoryManager().GetAllCategory();
            model.RecipesDB   = recipes;
            if (recipes == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Beispiel #14
0
        public ActionResult Edit(CategoriesListData model, HttpPostedFileBase picture)
        {
            model.SelectedRecipe = new RecipeManager().GetRecipeHeaderData(model.RecipesDB.ID);
            model.AllCategory    = new CategoryManager().GetAllCategory();
            if (ModelState.IsValid)
            {
                var pictureUrl = FileHelper.GetFileName(model.RecipesDB.ID.ToString(), picture);
                if (pictureUrl != null)
                {
                    model.RecipesDB.PictureUrl = pictureUrl;
                    List <string> pictureUrlElements = new List <string>(pictureUrl.Split(new string[] { "_" }, StringSplitOptions.None));
                    try
                    {
                        var files = Directory.GetFiles(Path.Combine(Server.MapPath("~"), "Upload\\Images")).ToList();
                        foreach (string file in files)
                        {
                            string        fileName    = Path.GetFileName(file);
                            List <string> fileElemets = new List <string>(fileName.Split(new string[] { "_" }, StringSplitOptions.None));
                            if (fileElemets.First().Equals(pictureUrlElements.First()))
                            {
                                System.IO.File.Delete(file);
                            }
                        }
                        picture.SaveAs(Path.Combine(Server.MapPath("~"), "Upload\\Images", pictureUrl));
                    }
                    catch { }
                }
                else if (picture != null)
                {
                    if (picture.ContentLength > 0)
                    {
                        ModelState.AddModelError("", "Nem megfelelő fájlformátum.");
                        return(View(model));
                    }
                }

                model.RecipesDB.FriendlyUrl     = FriendlyUrlHelper.RemoveDiacritics(model.RecipesDB.Title.Replace(" ", "_").ToLower());
                db.Entry(model.RecipesDB).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Comments", "Comments", new { recipeId = model.RecipesDB.ID }));
            }
            return(View(model));
        }
Beispiel #15
0
        public async Task<ActionResult> Create(CategoriesListData model)
        {
            if (ModelState.IsValid)
            {
                var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
                var user = await userManager.FindByIdAsync(User.Identity.GetUserId());

                var comment = new Comments
                {
                    CreatedDate = Convert.ToDateTime(DateTime.Now.ToString(new CultureInfo("hu-HU"))),
                    UserId = user.Id,
                    RecipesId = model.SelectedRecipe.ID,
                    Text = model.CommentsDB.Text
                };
                db.Comments.Add(comment);
                db.SaveChanges();
            }
            return PartialView(model);
        }
Beispiel #16
0
        public async Task <ActionResult> Create(CategoriesListData model, HttpPostedFileBase picture)
        {
            model.AllCategory = new CategoryManager().GetAllCategory();
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var user        = await userManager.FindByIdAsync(User.Identity.GetUserId());

            var recipe = new Recipes
            {
                CategoryID   = model.RecipesDB.CategoryID,
                Title        = model.RecipesDB.Title,
                HowToPrepare = model.RecipesDB.HowToPrepare,
                Ingredients  = model.RecipesDB.Ingredients,
                PrepareTime  = model.RecipesDB.PrepareTime,
                UserID       = user.Id,
                FriendlyUrl  = FriendlyUrlHelper.RemoveDiacritics(model.RecipesDB.Title.Replace(" ", "_"))
            };
            var pictureUrl = FileHelper.GetFileName("", picture);

            if (pictureUrl == null)
            {
                if (picture != null)
                {
                    if (picture.ContentLength > 0)
                    {
                        ModelState.AddModelError("", "Nem megfelelő fájlformátum.");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Nincs kép kiválasztva.");
                    return(View(model));
                }
            }
            else if (picture.ContentLength > 5000000)
            {
                ModelState.AddModelError("", "Túl nagy méretű kép.");
                return(View(model));
            }
            db.Recipes.Add(recipe);
            db.SaveChanges();

            int     id  = recipe.ID;
            Recipes rec = db.Recipes.Find(id);

            pictureUrl = FileHelper.GetFileName(rec.ID.ToString(), picture);
            if (pictureUrl != null)
            {
                rec.PictureUrl = pictureUrl;
                try
                {
                    picture.SaveAs(Path.Combine(Server.MapPath("~"), "Upload\\Images", pictureUrl));
                }
                catch { }
            }
            db.SaveChanges();

            return(RedirectToAction("Details"));
        }