├── ReadMe.txt
├── BlogProject.UI
├── Views
│ ├── _ViewStart.cshtml
│ ├── _ViewImports.cshtml
│ ├── Home
│ │ ├── List.cshtml
│ │ ├── Index.cshtml
│ │ ├── Components
│ │ │ └── CategoryMenu
│ │ │ │ └── _Default.cshtml
│ │ └── Details.cshtml
│ ├── Shared
│ │ ├── _Layout.cshtml
│ │ ├── _BlogList.cshtml
│ │ └── _Slider.cshtml
│ ├── Blog
│ │ ├── Index.cshtml
│ │ ├── Delete.cshtml
│ │ ├── Details.cshtml
│ │ ├── Create.cshtml
│ │ ├── Edit.cshtml
│ │ └── List.cshtml
│ └── Category
│ │ ├── AddOrUpdate.cshtml
│ │ └── List.cshtml
├── wwwroot
│ └── img
│ │ ├── 1.jpg
│ │ ├── 2.jpg
│ │ └── 3.jpg
├── appsettings.json
├── appsettings.Development.json
├── package.json
├── Models
│ └── HomeBlogModel.cs
├── Properties
│ └── launchSettings.json
├── Program.cs
├── BlogProject.UI.csproj
├── Controllers
│ ├── HomeController.cs
│ ├── CategoryController.cs
│ └── BlogController.cs
└── Startup.cs
├── BlogProject.Model
├── BlogProject.Model.csproj
└── Entity
│ ├── Category.cs
│ └── Blog.cs
├── BlogProject.DAL
├── BaseRepository
│ ├── IBlogRepository.cs
│ └── ICategoryRepository.cs
├── Context
│ └── ProjectContext.cs
├── BlogProject.DAL.csproj
├── Repository
│ ├── SeedData.cs
│ ├── EFCategoryRepository.cs
│ └── EFBlogRepository.cs
└── Migrations
│ ├── ProjectContextModelSnapshot.cs
│ ├── 20190612050141_InitialCreate.cs
│ └── 20190612050141_InitialCreate.Designer.cs
├── BlogProject.sln
├── .gitattributes
└── .gitignore
/ReadMe.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Burakkylmz/BlogProject/HEAD/ReadMe.txt
--------------------------------------------------------------------------------
/BlogProject.UI/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout= "~/Views/Shared/_Layout.cshtml";
3 | }
4 |
--------------------------------------------------------------------------------
/BlogProject.UI/wwwroot/img/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Burakkylmz/BlogProject/HEAD/BlogProject.UI/wwwroot/img/1.jpg
--------------------------------------------------------------------------------
/BlogProject.UI/wwwroot/img/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Burakkylmz/BlogProject/HEAD/BlogProject.UI/wwwroot/img/2.jpg
--------------------------------------------------------------------------------
/BlogProject.UI/wwwroot/img/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Burakkylmz/BlogProject/HEAD/BlogProject.UI/wwwroot/img/3.jpg
--------------------------------------------------------------------------------
/BlogProject.UI/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*"
8 | }
9 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @using BlogProject.UI.Models
3 | @using BlogProject.Model.Entity
4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Home/List.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "List";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 |
List
8 |
9 |
--------------------------------------------------------------------------------
/BlogProject.Model/BlogProject.Model.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/BlogProject.UI/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/BlogProject.UI/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "BlogProject.UI",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "dependencies": {
10 | "bootstrap": "4.3.1"
11 | },
12 | "keywords": [],
13 | "author": "",
14 | "license": "ISC"
15 | }
16 |
--------------------------------------------------------------------------------
/BlogProject.Model/Entity/Category.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace BlogProject.Model.Entity
6 | {
7 | public class Category
8 | {
9 | public int Id { get; set; }
10 | public string Name { get; set; }
11 |
12 | public virtual List Blogs { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Shared/_Layout.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | @ViewBag.Title
7 |
8 |
9 |
10 |
11 |
12 |
13 | @RenderBody()
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/BlogProject.UI/Models/HomeBlogModel.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.Model.Entity;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace BlogProject.UI.Models
8 | {
9 | public class HomeBlogModel
10 | {
11 | public virtual List SliderBlogs { get; set; }
12 | public virtual List HomeBlogs { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Blog/Index.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Index";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model IEnumerable
8 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Blog/Delete.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Delete";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model Blog
8 |
9 |
10 | @Model.Title isimli kaydı silmek istiyor musunuz?
11 |
12 |
13 |
17 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Index";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model HomeBlogModel
8 |
9 |
10 |
11 |
12 | @await Component.InvokeAsync("CategoryMenu")
13 |
14 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/BlogProject.DAL/BaseRepository/IBlogRepository.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.Model.Entity;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace BlogProject.DAL.BaseRepository
8 | {
9 | public interface IBlogRepository
10 | {
11 | Blog GetById(int id);
12 | IQueryable GetAll();
13 | void AddBlog(Blog entity);
14 | void UpdateBlog(Blog entity);
15 | void SaveBlog(Blog entity);
16 | void DeleteBlog(int id);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Context/ProjectContext.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.Model.Entity;
2 | using Microsoft.EntityFrameworkCore;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace BlogProject.DAL.Context
8 | {
9 | public class ProjectContext : DbContext
10 | {
11 | public ProjectContext(DbContextOptions options) : base(options)
12 | {
13 |
14 | }
15 |
16 | public DbSet Blogs { get; set; }
17 | public DbSet Categories { get; set; }
18 |
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Home/Components/CategoryMenu/_Default.cshtml:
--------------------------------------------------------------------------------
1 | @*
2 | For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
3 | *@
4 |
5 | @model IEnumerable
6 |
7 |
--------------------------------------------------------------------------------
/BlogProject.DAL/BaseRepository/ICategoryRepository.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.Model.Entity;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace BlogProject.DAL.BaseRepository
8 | {
9 | public interface ICategoryRepository
10 | {
11 | Category GetById(int id);
12 | IQueryable GetAll();
13 | void AddCategory(Category entity);
14 | void UpdateCategory(Category entity);
15 | void DeleteCategory(int id);
16 | void SaveCategory(Category entity);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Category/AddOrUpdate.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "AddOrUpdate";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model Category
8 |
9 |
10 |
Create Caregory
11 |
12 |
13 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/BlogProject.Model/Entity/Blog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace BlogProject.Model.Entity
6 | {
7 | public class Blog
8 | {
9 | public int Id { get; set; }
10 | public string Title { get; set; }
11 | public string Description { get; set; }
12 | public DateTime? AddDate { get; set; }
13 | public bool isActive { get; set; }
14 | public string ImageUrl { get; set; }
15 | public bool isHome { get; set; }
16 | public bool isSlider { get; set; }
17 | public string Body { get; set; }
18 |
19 | public int CategoryId { get; set; }
20 | public virtual Category Category { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/BlogProject.UI/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:57992",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "BlogProject.UI": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/BlogProject.DAL/BlogProject.DAL.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | ..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/BlogProject.UI/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore;
7 | using Microsoft.AspNetCore.Hosting;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.Logging;
10 |
11 | namespace BlogProject.UI
12 | {
13 | public class Program
14 | {
15 | public static void Main(string[] args)
16 | {
17 | CreateWebHostBuilder(args).Build().Run();
18 | }
19 |
20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21 | WebHost.CreateDefaultBuilder(args)
22 | .UseDefaultServiceProvider(options => options.ValidateScopes = false)
23 | .UseStartup();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Blog/Details.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Details";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model Blog
8 |
9 |
10 |
11 |
12 | @*@await Components.InvokeAsync("CategoryMenu")*@
13 |
14 |
15 |
18 |

19 |
20 |
21 |
@Model.Title
22 |
@Model.Description
23 |
@Html.Raw(Model.Body)
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/BlogProject.UI/BlogProject.UI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 | InProcess
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Shared/_BlogList.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @*
3 | For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
4 | *@
5 |
6 |
7 | @model IEnumerable
8 |
9 | @if (Model.Count() == 0)
10 | {
11 | There is no record
12 | }
13 | else
14 | {
15 | @foreach (var item in Model)
16 | {
17 |
18 |
21 |
![Card image cap]()
22 |
23 |
24 |
@item.Title
25 |
@item.Description
26 |
Blog Details
27 |
28 |
29 | }
30 | }
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Blog/Create.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Create";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model Blog
8 |
9 |
10 |
Create Blog
11 |
12 |
13 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/BlogProject.UI/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using BlogProject.DAL.BaseRepository;
6 | using BlogProject.UI.Models;
7 | using Microsoft.AspNetCore.Mvc;
8 |
9 | namespace BlogProject.UI.Controllers
10 | {
11 | public class HomeController : Controller
12 | {
13 | private IBlogRepository blogRepository;
14 |
15 | public HomeController(IBlogRepository repository)
16 | {
17 | blogRepository = repository;
18 | }
19 |
20 | [HttpGet]
21 | public IActionResult Index()
22 | {
23 | var model = new HomeBlogModel();
24 |
25 | model.HomeBlogs = blogRepository.GetAll().Where(x => x.isActive && x.isHome).ToList();
26 | model.SliderBlogs = blogRepository.GetAll().Where(x => x.isActive && x.isSlider).ToList();
27 |
28 | return View(model);
29 | }
30 |
31 | [HttpGet]
32 | public IActionResult List()
33 | {
34 | return View();
35 | }
36 |
37 | [HttpGet]
38 | public IActionResult Details()
39 | {
40 | return View();
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Home/Details.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Details";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 |
8 |
19 |
20 |
21 |

22 |
25 |
26 |
Special title treatment
27 |
With supporting text below as a neutural lead-in to additional content
28 |
Go somewhere
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/BlogProject.UI/Controllers/CategoryController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using BlogProject.DAL.BaseRepository;
6 | using BlogProject.Model.Entity;
7 | using Microsoft.AspNetCore.Mvc;
8 |
9 | namespace BlogProject.UI.Controllers
10 | {
11 | public class CategoryController : Controller
12 | {
13 | private ICategoryRepository repository;
14 |
15 | public CategoryController(ICategoryRepository _repo)
16 | {
17 | repository = _repo;
18 | }
19 |
20 | public IActionResult Index()
21 | {
22 | return View();
23 | }
24 |
25 | public IActionResult List()
26 | {
27 | return View(repository.GetAll());
28 | }
29 |
30 | [HttpGet]
31 | public IActionResult AddOrUpdate(int? id)
32 | {
33 | if (id==null)
34 | {
35 | return View(new Category());
36 | }
37 | else
38 | {
39 | return View(repository.GetById((int)id));
40 | }
41 | }
42 |
43 | [HttpPost]
44 | public IActionResult AddOrUpdate(Category entity)
45 | {
46 | if (ModelState.IsValid)
47 | {
48 | repository.SaveCategory(entity);
49 | TempData["message"] = $"{entity.Name} kayıt edildi";
50 | return RedirectToAction("List");
51 | }
52 |
53 | return View(entity);
54 | }
55 |
56 | [HttpGet]
57 | public IActionResult Delete(int id)
58 | {
59 | repository.DeleteCategory(id);
60 | TempData["message"] = $"{id} numaralı kayıt silinidi";
61 | return RedirectToAction("List");
62 |
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Category/List.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "List";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model IEnumerable
8 |
9 |
10 |
Category List
11 |
12 |
13 |
14 | @if (Model.Count()> 0)
15 | {
16 |
17 |
18 |
19 | | ID |
20 | Name |
21 | |
22 |
23 |
24 |
25 | @foreach (var item in Model)
26 | {
27 |
28 | | @item.Id |
29 | @item.Name |
30 |
31 |
32 | Details
33 |
34 |
35 | Delete
36 |
37 | |
38 |
39 | }
40 |
41 |
42 | }
43 | else
44 | {
45 |
46 | Kategory Eklenmmeiş
47 |
48 | }
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Repository/SeedData.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.DAL.Context;
2 | using BlogProject.Model.Entity;
3 | using Microsoft.AspNetCore.Builder;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 | using System.Text;
10 |
11 | namespace BlogProject.DAL.Repository
12 | {
13 | public class SeedData
14 | {
15 | public static void Seed(IApplicationBuilder app)
16 | {
17 | ProjectContext context = app.ApplicationServices.GetRequiredService();
18 |
19 | context.Database.Migrate();
20 |
21 | if (!context.Categories.Any())
22 | {
23 | context.Categories.AddRange(
24 | new Category() { Name= "Category1"},
25 | new Category() { Name = "Category2" },
26 | new Category() { Name = "Category3" }
27 | );
28 |
29 | context.SaveChanges();
30 | }
31 |
32 | if (!context.Blogs.Any())
33 | {
34 | context.Blogs.AddRange(
35 | new Blog() { Title="Blog Title 1", Description="Blog Description", Body="Blog Body 1", ImageUrl="1.jpeg", AddDate=DateTime.Now.AddDays(-5), isActive=true, CategoryId=1},
36 | new Blog() { Title = "Blog Title 2", Description = "Blog Description", Body = "Blog Body 2", ImageUrl = "2.jpeg", AddDate = DateTime.Now.AddDays(-5), isActive = true, CategoryId = 2},
37 | new Blog() { Title = "Blog Title 3", Description = "Blog Description", Body = "Blog Body 3", ImageUrl = "3.jpeg", AddDate = DateTime.Now.AddDays(-5), isActive = true, CategoryId = 3 },
38 | new Blog() { Title = "Blog Title 4", Description = "Blog Description", Body = "Blog Body 4", ImageUrl = "4.jpeg", AddDate = DateTime.Now.AddDays(-5), isActive = true, CategoryId = 4 }
39 | );
40 |
41 | context.SaveChanges();
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Repository/EFCategoryRepository.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.DAL.BaseRepository;
2 | using BlogProject.DAL.Context;
3 | using BlogProject.Model.Entity;
4 | using Microsoft.EntityFrameworkCore.Internal;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 |
10 | namespace BlogProject.DAL.Repository
11 | {
12 | public class EFCategoryRepository:ICategoryRepository
13 | {
14 | private ProjectContext context;
15 |
16 | public EFCategoryRepository(ProjectContext _context)
17 | {
18 | context = _context;
19 | }
20 |
21 | public void AddCategory(Category entity)
22 | {
23 | context.Categories.Add(entity);
24 | context.SaveChanges();
25 | }
26 |
27 | public void DeleteCategory(int id)
28 | {
29 | var category = context.Categories.FirstOrDefault(x => x.Id == id);
30 |
31 | if (category != null)
32 | {
33 | context.Categories.Remove(category);
34 | context.SaveChanges();
35 | }
36 | }
37 |
38 | public IQueryable GetAll()
39 | {
40 | return context.Categories;
41 | }
42 |
43 | public Category GetById(int id)
44 | {
45 | return context.Categories.FirstOrDefault(x => x.Id == id);
46 | }
47 |
48 | public void SaveCategory(Category entity)
49 | {
50 | if (entity.Id == 0)
51 | {
52 | context.Categories.Add(entity);
53 | }
54 | else
55 | {
56 | var category = GetById(entity.Id);
57 | if (category != null)
58 | {
59 | category.Name = entity.Name;
60 | }
61 | }
62 |
63 | context.SaveChanges();
64 | }
65 |
66 | public void UpdateCategory(Category entity)
67 | {
68 | context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
69 | context.SaveChanges();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Blog/Edit.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "Edit";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 |
7 | @model Blog
8 |
9 |
68 |
69 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Shared/_Slider.cshtml:
--------------------------------------------------------------------------------
1 | @*
2 | For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
3 | *@
4 |
5 | @model IEnumerable
6 |
7 |
8 |
9 | @for (int i = 0; i < Model.Count(); i++)
10 | {
11 | if (i == 0)
12 | {
13 |
14 | }
15 | else
16 | {
17 |
18 | }
19 | }
20 |
21 |
22 |
23 | @{ var index = 0;}
24 | @foreach (var item in Model)
25 | {
26 | if (index == 0)
27 | {
28 |
29 |

30 |
31 |
@item.Title
32 |
@item.Description
33 |
34 |
35 |
36 | index++;
37 | }
38 | else
39 | {
40 |
41 |

42 |
43 |
@item.Title
44 |
@item.Description
45 |
46 |
47 | }
48 | }
49 |
50 |
51 |
52 |
53 | Previous
54 |
55 |
56 |
57 | Next
58 |
59 |
60 |
--------------------------------------------------------------------------------
/BlogProject.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28922.388
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlogProject.UI", "BlogProject.UI\BlogProject.UI.csproj", "{7BBF2BBF-7828-4107-94B8-796A899EA69B}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlogProject.DAL", "BlogProject.DAL\BlogProject.DAL.csproj", "{28DB1331-EB51-4010-95C9-17EAA0709D15}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlogProject.Model", "BlogProject.Model\BlogProject.Model.csproj", "{43EBD1E8-844B-4307-A99C-61DDD217A5EA}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA84AD52-23B6-4F94-A763-63D61FFA3611}"
13 | ProjectSection(SolutionItems) = preProject
14 | ReadMe.txt = ReadMe.txt
15 | EndProjectSection
16 | EndProject
17 | Global
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Release|Any CPU = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {7BBF2BBF-7828-4107-94B8-796A899EA69B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {7BBF2BBF-7828-4107-94B8-796A899EA69B}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {7BBF2BBF-7828-4107-94B8-796A899EA69B}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {7BBF2BBF-7828-4107-94B8-796A899EA69B}.Release|Any CPU.Build.0 = Release|Any CPU
27 | {28DB1331-EB51-4010-95C9-17EAA0709D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {28DB1331-EB51-4010-95C9-17EAA0709D15}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {28DB1331-EB51-4010-95C9-17EAA0709D15}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {28DB1331-EB51-4010-95C9-17EAA0709D15}.Release|Any CPU.Build.0 = Release|Any CPU
31 | {43EBD1E8-844B-4307-A99C-61DDD217A5EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32 | {43EBD1E8-844B-4307-A99C-61DDD217A5EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
33 | {43EBD1E8-844B-4307-A99C-61DDD217A5EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {43EBD1E8-844B-4307-A99C-61DDD217A5EA}.Release|Any CPU.Build.0 = Release|Any CPU
35 | EndGlobalSection
36 | GlobalSection(SolutionProperties) = preSolution
37 | HideSolutionNode = FALSE
38 | EndGlobalSection
39 | GlobalSection(ExtensibilityGlobals) = postSolution
40 | SolutionGuid = {2B022798-6CB3-4D48-940E-F106EDC0B435}
41 | EndGlobalSection
42 | EndGlobal
43 |
--------------------------------------------------------------------------------
/BlogProject.UI/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using BlogProject.DAL.BaseRepository;
7 | using BlogProject.DAL.Context;
8 | using BlogProject.DAL.Repository;
9 | using Microsoft.AspNetCore.Builder;
10 | using Microsoft.AspNetCore.Hosting;
11 | using Microsoft.AspNetCore.Http;
12 | using Microsoft.EntityFrameworkCore;
13 | using Microsoft.Extensions.Configuration;
14 | using Microsoft.Extensions.DependencyInjection;
15 | using Microsoft.Extensions.FileProviders;
16 |
17 | namespace BlogProject.UI
18 | {
19 | public class Startup
20 | {
21 | public IConfiguration Configuration { get; }
22 |
23 | public Startup(IConfiguration configuration)
24 | {
25 | Configuration = configuration;
26 | }
27 | // This method gets called by the runtime. Use this method to add services to the container.
28 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
29 | public void ConfigureServices(IServiceCollection services)
30 | {
31 | var conntection = "Server=DESKTOP-TJVLSIK;Database=BlogProjectDB;Integrated Security=true;";
32 | services.AddDbContext
33 | (options => options.UseSqlServer(conntection));
34 | services.AddTransient();
35 | services.AddTransient();
36 | services.AddMvc();
37 | }
38 |
39 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
40 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
41 | {
42 | if (env.IsDevelopment())
43 | {
44 | app.UseDeveloperExceptionPage();
45 | }
46 |
47 | app.UseStaticFiles();
48 |
49 | app.UseStatusCodePages();
50 |
51 | app.UseMvc(routes =>
52 | {
53 | routes.MapRoute(
54 | name: "default",
55 | template: "{controller=Home}/{action=Index}/{id?}"
56 | );
57 | });
58 |
59 | app.UseStaticFiles(new StaticFileOptions
60 | {
61 | FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "node_modules")), RequestPath = "/modules"
62 | });
63 |
64 | SeedData.Seed(app);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Repository/EFBlogRepository.cs:
--------------------------------------------------------------------------------
1 | using BlogProject.DAL.BaseRepository;
2 | using BlogProject.DAL.Context;
3 | using BlogProject.Model.Entity;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 |
9 | namespace BlogProject.DAL.Repository
10 | {
11 | public class EFBlogRepository:IBlogRepository
12 | {
13 | private ProjectContext context;
14 |
15 | public EFBlogRepository(ProjectContext _context)
16 | {
17 | context = _context;
18 | }
19 |
20 | public void AddBlog(Blog entity)
21 | {
22 | context.Blogs.Add(entity);
23 | context.SaveChanges();
24 | }
25 |
26 | public void DeleteBlog(int id)
27 | {
28 | var blog = context.Blogs.FirstOrDefault(x => x.Id == id);
29 |
30 | if (blog != null)
31 | {
32 | context.Blogs.Remove(blog);
33 | context.SaveChanges();
34 | }
35 | }
36 |
37 | public IQueryable GetAll()
38 | {
39 | return context.Blogs;
40 | }
41 |
42 | public Blog GetById(int id)
43 | {
44 | return context.Blogs.FirstOrDefault(x => x.Id == id);
45 | }
46 |
47 | public void SaveBlog(Blog entity)
48 | {
49 | if (entity.Id == 0)
50 | {
51 | entity.AddDate = DateTime.Now;
52 | context.Blogs.Add(entity);
53 | }
54 | else
55 | {
56 | var blog = GetById(entity.Id);
57 |
58 | if (blog != null)
59 | {
60 | blog.Title = entity.Title;
61 | blog.Description = entity.Description;
62 | blog.CategoryId = entity.CategoryId;
63 | blog.ImageUrl = entity.ImageUrl;
64 | blog.isHome = entity.isHome;
65 | blog.isActive = entity.isActive;
66 | blog.isSlider = entity.isSlider;
67 | blog.Body = entity.Body;
68 |
69 | }
70 | }
71 |
72 | context.SaveChanges();
73 | }
74 |
75 | public void UpdateBlog(Blog entity)
76 | {
77 | var blog = GetById(entity.Id);
78 |
79 | if (blog != null)
80 | {
81 | blog.Title = entity.Title;
82 | blog.Description = entity.Description;
83 | blog.CategoryId = entity.CategoryId;
84 | blog.ImageUrl = entity.ImageUrl;
85 |
86 | context.SaveChanges();
87 | }
88 |
89 | context.SaveChanges();
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Migrations/ProjectContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using BlogProject.DAL.Context;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace BlogProject.DAL.Migrations
10 | {
11 | [DbContext(typeof(ProjectContext))]
12 | partial class ProjectContextModelSnapshot : ModelSnapshot
13 | {
14 | protected override void BuildModel(ModelBuilder modelBuilder)
15 | {
16 | #pragma warning disable 612, 618
17 | modelBuilder
18 | .HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
19 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
20 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
21 |
22 | modelBuilder.Entity("BlogProject.Model.Entity.Blog", b =>
23 | {
24 | b.Property("Id")
25 | .ValueGeneratedOnAdd()
26 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
27 |
28 | b.Property("AddDate");
29 |
30 | b.Property("Body");
31 |
32 | b.Property("CategoryId");
33 |
34 | b.Property("Description");
35 |
36 | b.Property("ImageUrl");
37 |
38 | b.Property("Title");
39 |
40 | b.Property("isActive");
41 |
42 | b.Property("isHome");
43 |
44 | b.Property("isSlider");
45 |
46 | b.HasKey("Id");
47 |
48 | b.HasIndex("CategoryId");
49 |
50 | b.ToTable("Blogs");
51 | });
52 |
53 | modelBuilder.Entity("BlogProject.Model.Entity.Category", b =>
54 | {
55 | b.Property("Id")
56 | .ValueGeneratedOnAdd()
57 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
58 |
59 | b.Property("Name");
60 |
61 | b.HasKey("Id");
62 |
63 | b.ToTable("Categories");
64 | });
65 |
66 | modelBuilder.Entity("BlogProject.Model.Entity.Blog", b =>
67 | {
68 | b.HasOne("BlogProject.Model.Entity.Category", "Category")
69 | .WithMany("Blogs")
70 | .HasForeignKey("CategoryId")
71 | .OnDelete(DeleteBehavior.Cascade);
72 | });
73 | #pragma warning restore 612, 618
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Migrations/20190612050141_InitialCreate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.Metadata;
3 | using Microsoft.EntityFrameworkCore.Migrations;
4 |
5 | namespace BlogProject.DAL.Migrations
6 | {
7 | public partial class InitialCreate : Migration
8 | {
9 | protected override void Up(MigrationBuilder migrationBuilder)
10 | {
11 | migrationBuilder.CreateTable(
12 | name: "Categories",
13 | columns: table => new
14 | {
15 | Id = table.Column(nullable: false)
16 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
17 | Name = table.Column(nullable: true)
18 | },
19 | constraints: table =>
20 | {
21 | table.PrimaryKey("PK_Categories", x => x.Id);
22 | });
23 |
24 | migrationBuilder.CreateTable(
25 | name: "Blogs",
26 | columns: table => new
27 | {
28 | Id = table.Column(nullable: false)
29 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
30 | Title = table.Column(nullable: true),
31 | Description = table.Column(nullable: true),
32 | AddDate = table.Column(nullable: true),
33 | isActive = table.Column(nullable: false),
34 | ImageUrl = table.Column(nullable: true),
35 | isHome = table.Column(nullable: false),
36 | isSlider = table.Column(nullable: false),
37 | Body = table.Column(nullable: true),
38 | CategoryId = table.Column(nullable: false)
39 | },
40 | constraints: table =>
41 | {
42 | table.PrimaryKey("PK_Blogs", x => x.Id);
43 | table.ForeignKey(
44 | name: "FK_Blogs_Categories_CategoryId",
45 | column: x => x.CategoryId,
46 | principalTable: "Categories",
47 | principalColumn: "Id",
48 | onDelete: ReferentialAction.Cascade);
49 | });
50 |
51 | migrationBuilder.CreateIndex(
52 | name: "IX_Blogs_CategoryId",
53 | table: "Blogs",
54 | column: "CategoryId");
55 | }
56 |
57 | protected override void Down(MigrationBuilder migrationBuilder)
58 | {
59 | migrationBuilder.DropTable(
60 | name: "Blogs");
61 |
62 | migrationBuilder.DropTable(
63 | name: "Categories");
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/BlogProject.DAL/Migrations/20190612050141_InitialCreate.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using BlogProject.DAL.Context;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Migrations;
8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
9 |
10 | namespace BlogProject.DAL.Migrations
11 | {
12 | [DbContext(typeof(ProjectContext))]
13 | [Migration("20190612050141_InitialCreate")]
14 | partial class InitialCreate
15 | {
16 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
17 | {
18 | #pragma warning disable 612, 618
19 | modelBuilder
20 | .HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
21 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
23 |
24 | modelBuilder.Entity("BlogProject.Model.Entity.Blog", b =>
25 | {
26 | b.Property("Id")
27 | .ValueGeneratedOnAdd()
28 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
29 |
30 | b.Property("AddDate");
31 |
32 | b.Property("Body");
33 |
34 | b.Property("CategoryId");
35 |
36 | b.Property("Description");
37 |
38 | b.Property("ImageUrl");
39 |
40 | b.Property("Title");
41 |
42 | b.Property("isActive");
43 |
44 | b.Property("isHome");
45 |
46 | b.Property("isSlider");
47 |
48 | b.HasKey("Id");
49 |
50 | b.HasIndex("CategoryId");
51 |
52 | b.ToTable("Blogs");
53 | });
54 |
55 | modelBuilder.Entity("BlogProject.Model.Entity.Category", b =>
56 | {
57 | b.Property("Id")
58 | .ValueGeneratedOnAdd()
59 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
60 |
61 | b.Property("Name");
62 |
63 | b.HasKey("Id");
64 |
65 | b.ToTable("Categories");
66 | });
67 |
68 | modelBuilder.Entity("BlogProject.Model.Entity.Blog", b =>
69 | {
70 | b.HasOne("BlogProject.Model.Entity.Category", "Category")
71 | .WithMany("Blogs")
72 | .HasForeignKey("CategoryId")
73 | .OnDelete(DeleteBehavior.Cascade);
74 | });
75 | #pragma warning restore 612, 618
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/BlogProject.UI/Views/Blog/List.cshtml:
--------------------------------------------------------------------------------
1 |
2 | @{
3 | ViewData["Title"] = "List";
4 | Layout = "~/Views/Shared/_Layout.cshtml";
5 | }
6 | @model IEnumerable
7 |
8 |
9 |
Blog List
10 |
11 |
Create
12 |
13 |
14 |
15 | @if (Model.Count() > 0)
16 | {
17 |
18 |
19 |
20 | | Id |
21 | Image |
22 | Title |
23 | Date |
24 | Is Active |
25 | Is Home |
26 | Is Slider |
27 | |
28 |
29 |
30 |
31 | @foreach (var item in Model)
32 | {
33 |
34 | | @item.Id |
35 |
36 |
37 | |
38 | @item.Title |
39 | @item.AddDate |
40 |
41 | @if (item.isActive)
42 | {
43 |
44 | }
45 | else
46 | {
47 |
48 | }
49 | |
50 |
51 | @if (item.isHome)
52 | {
53 |
54 | }
55 | else
56 | {
57 |
58 | }
59 | |
60 |
61 | @if (item.isSlider)
62 | {
63 |
64 | }
65 | else
66 | {
67 |
68 | }
69 | |
70 |
71 | Edit
72 | Delete
73 | |
74 |
75 | }
76 |
77 |
78 | }
79 | else
80 | {
81 |
82 | Blog eklenmemiştir.
83 |
84 | }
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/BlogProject.UI/Controllers/BlogController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using BlogProject.DAL.BaseRepository;
7 | using BlogProject.Model.Entity;
8 | using Microsoft.AspNetCore.Http;
9 | using Microsoft.AspNetCore.Mvc;
10 | using Microsoft.AspNetCore.Mvc.Rendering;
11 | using Microsoft.EntityFrameworkCore;
12 |
13 | namespace BlogProject.UI.Controllers
14 | {
15 | public class BlogController : Controller
16 | {
17 |
18 | private IBlogRepository _blogRepository;
19 | private ICategoryRepository _categoryRepository;
20 |
21 |
22 | public BlogController(ICategoryRepository categoryRepo, IBlogRepository blogRepo)
23 | {
24 | _blogRepository = blogRepo;
25 | _categoryRepository = categoryRepo;
26 | }
27 |
28 | public IActionResult Index(int? id, string q)
29 | {
30 | var query = _blogRepository.GetAll().Where(x => x.isActive);
31 |
32 | if (id != null)
33 | {
34 | query = query.Where(x => x.CategoryId == id);
35 | }
36 |
37 | if (!string.IsNullOrEmpty(q))
38 | {
39 | query = query.Where(x => EF.Functions.Like(x.Title, "%" + q + "%") || EF.Functions.Like(x.Description, "%" + q + "%") || EF.Functions.Like(x.Body, "%" + q + "%"));
40 | }
41 |
42 | return View(query.OrderByDescending(x=> x.AddDate));
43 | }
44 |
45 |
46 | public IActionResult Details(int id)
47 | {
48 | return View(_blogRepository.GetById(id));
49 | }
50 |
51 | public IActionResult List()
52 | {
53 | return View(_blogRepository.GetAll());
54 | }
55 |
56 | [HttpGet]
57 | public IActionResult Create(BlogController entity)
58 | {
59 | ViewBag.Categories = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Name");
60 |
61 | return View(new Blog());
62 | }
63 |
64 | [HttpPost]
65 | public IActionResult Create(Blog entity)
66 | {
67 | if (ModelState.IsValid)
68 | {
69 | _blogRepository.SaveBlog(entity);
70 | TempData["message"] = $"{entity.Title} kayıt edildi";
71 | return RedirectToAction("List");
72 | }
73 |
74 | ViewBag.Categories = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Name");
75 | return View(entity);
76 | }
77 |
78 | public IActionResult Edit(int id)
79 | {
80 | ViewBag.Categories = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Name");
81 |
82 | return View(_blogRepository.GetById(id));
83 | }
84 |
85 | public async Task Edit(Blog entity, IFormFile file)
86 | {
87 | if (ModelState.IsValid)
88 | {
89 | if (file != null)
90 | {
91 | var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\ing", file.FileName);
92 |
93 | using (var stream = new FileStream(path, FileMode.Create))
94 | {
95 | await file.CopyToAsync(stream);
96 |
97 | entity.ImageUrl = file.FileName;
98 | }
99 | }
100 |
101 | _blogRepository.SaveBlog(entity);
102 | TempData["message"] = $"{ entity.Title} kayıt edildi.";
103 | return RedirectToAction("List");
104 | }
105 |
106 | ViewBag.Categories = new SelectList(_categoryRepository.GetAll(), "CategoryId", "Name");
107 | return View(entity);
108 | }
109 |
110 | public IActionResult Delete(int id)
111 | {
112 | return View(_blogRepository.GetById(id));
113 | }
114 |
115 | [HttpPost, ActionName("Delete")]
116 | public IActionResult DeleteConfirmed(int Id)
117 | {
118 | _blogRepository.DeleteBlog(Id);
119 | TempData["message"] = $"{Id} numaralı kayıt edildi.";
120 | return RedirectToAction("List");
121 | }
122 |
123 | }
124 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------