Example #1
0
        public async Task <IActionResult> Edit(int Id, EventPost eventPost)
        //Here is where I realized I messed up naming this event *Fixed
        {
            ViewBag.CategoryId = new SelectList(context.Categories.OrderBy(x => x.Sorting), "Id", "Name", eventPost.CategoryId);

            if (ModelState.IsValid)
            {
                eventPost.Slug = eventPost.Name.ToLower().Replace(" ", "-");

                var slug = await context.EventPosts.Where(x => x.Id != Id).FirstOrDefaultAsync(x => x.Slug == eventPost.Slug);

                if (slug != null)
                {
                    ModelState.AddModelError("", "This event alreay exists");
                    return(View(eventPost));
                }

                context.Update(eventPost);
                await context.SaveChangesAsync();

                TempData["Success"] = "The event has been updated!";


                return(RedirectToAction("Index"));
            }
            return(View(eventPost));
        }
Example #2
0
        public async Task <IActionResult> Edit(Page page)
        {
            if (ModelState.IsValid)
            {
                page.Slug = page.Id == 1 ? "home" : page.Title.ToLower().Replace(" ", "-");

                var slug = await context.Pages.Where(x => x.Id != page.Id).FirstOrDefaultAsync(x => x.Slug == page.Slug);

                if (slug != null)
                {
                    ModelState.AddModelError("", "The page alreay exists");
                    return(View(page));
                }

                context.Update(page);
                await context.SaveChangesAsync();

                TempData["Success"] = "The page has been edited!";


                return(RedirectToAction("Edit", new { id = page.Id }));
            }
            return(View(page));
        }
Example #3
0
        public async Task <IActionResult> Edit(int id, Category category)
        {
            if (ModelState.IsValid)
            {
                category.Slug = category.Name.ToLower().Replace(" ", "-");

                var slug = await context.Categories.Where(x => x.Id != id).FirstOrDefaultAsync(x => x.Slug == category.Slug);

                if (slug != null)
                {
                    ModelState.AddModelError("", "The category alreay exists");
                    return(View(category));
                }

                context.Update(category);
                await context.SaveChangesAsync();

                TempData["Success"] = "The category has been edited!";


                return(RedirectToAction("Edit", new { id }));
            }
            return(View(category));
        }