public IActionResult CreatePost(AdminPostDto postdto) { User user = GetUser(); Store store = StoreService.GetStore(postdto.StoreId, user); Category category = CategoryService.GetCategory(postdto.CategoryId); PostService.PostSave(postdto, store, category); return(RedirectToAction("Index")); }
public IActionResult Index() { User user = GetUser(); List <StoreDto> storesdtos = StoreService.GetStoresDto(user); List <CategoryDto> categorydtos = CategoryService.GetCategoriesDto(); AdminPostDto post = new AdminPostDto { StoreDto = storesdtos, CategoryDto = categorydtos }; return(View(post)); }
public void PostSave(AdminPostDto postdto, Store store, Category category) { Post post = new Post { Store = store, Title = postdto.Title, Content = postdto.Content, Category = category, Points = postdto.Points }; post.CreateDate = DateTime.Now; Context.Post.Add(post); Context.SaveChanges(); if (post.Id == 0) { throw new Exception("Error saving post"); } }