Skip to content

Commit dc99b7c

Browse files
author
Ömer Selim
committed
Haber görüntüleme sitesi hazırlandı
1 parent 0a2a1a4 commit dc99b7c

15 files changed

+389
-79
lines changed

Yonetim.BLL/Repository/Repository.cs

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Data.Entity.Validation;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -38,6 +39,37 @@ public void Insert(HaberViewModel model)
3839

3940
}
4041
}
42+
public void Update(HaberViewModel model)
43+
{
44+
MyContext db = new MyContext();
45+
using (db.Database.BeginTransaction())
46+
{
47+
try
48+
{
49+
var haber = db.Haberler.Find(model.Id);
50+
if (haber == null)
51+
throw new DbEntityValidationException("Güncellenecek haber bulunamadı");
52+
53+
var kategoriler = db.Kategoriler.Where(x => model.Kategoriler.Contains(x.Id)).ToList();
54+
55+
haber.Baslik = model.Baslik;
56+
haber.Icerik = model.Icerik;
57+
haber.Keywords = model.Keywords;
58+
haber.YayindaMi = model.YayindaMi;
59+
db.SaveChanges();
60+
61+
haber.Kategoriler.Clear();
62+
haber.Kategoriler = kategoriler;
63+
db.SaveChanges();
64+
db.Database.CurrentTransaction.Commit();
65+
}
66+
catch(DbEntityValidationException ex)
67+
{
68+
db.Database.CurrentTransaction.Rollback();
69+
throw ex;
70+
}
71+
}
72+
}
4173
}
4274
public class KategoriRepo : RepositoryBase<Kategori, int> { }
4375
}

Yonetim.BLL/Settings/SiteSettings.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.RegularExpressions;
6+
using System.Threading.Tasks;
7+
8+
namespace Yonetim.BLL.Settings
9+
{
10+
public class SiteSettings
11+
{
12+
public static string GetPlainTextFromHtml(string htmlString)
13+
{
14+
if (string.IsNullOrEmpty(htmlString))
15+
return string.Empty;
16+
string htmlTagPattern = "<.*?>";
17+
var regexCss = new Regex("(\\<script(.+?)\\</script\\>)|(\\<style(.+?)\\</style\\>)", RegexOptions.Singleline | RegexOptions.IgnoreCase);
18+
htmlString = regexCss.Replace(htmlString, string.Empty);
19+
htmlString = Regex.Replace(htmlString, htmlTagPattern, string.Empty);
20+
htmlString = Regex.Replace(htmlString, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
21+
htmlString = htmlString.Replace("&nbsp;", string.Empty);
22+
23+
return htmlString;
24+
}
25+
}
26+
}

Yonetim.BLL/Yonetim.BLL.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="Properties\AssemblyInfo.cs" />
5353
<Compile Include="Repository\Repository.cs" />
5454
<Compile Include="Repository\RepositoryBase.cs" />
55+
<Compile Include="Settings\SiteSettings.cs" />
5556
</ItemGroup>
5657
<ItemGroup>
5758
<ProjectReference Include="..\Yonetim.DAL\Yonetim.DAL.csproj">
@@ -67,9 +68,7 @@
6768
<None Include="App.config" />
6869
<None Include="packages.config" />
6970
</ItemGroup>
70-
<ItemGroup>
71-
<Folder Include="Settings\" />
72-
</ItemGroup>
71+
<ItemGroup />
7372
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7473
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7574
Other similar extension points exist, see Microsoft.Common.targets.

Yonetim.UI.Web/Content/Site.css

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.tek{
1+
@import url('https://fonts.googleapis.com/css?family=Alegreya|Alegreya+Sans:400,400i,500,900,900i|Sedgwick+Ave+Display&subset=latin-ext');
2+
.tek{
23
background-color:tomato;
34
color:azure;
45
}
@@ -12,4 +13,19 @@
1213
border:2px solid white;
1314
padding:0 5px 0 5px;
1415
background-color:royalblue;
16+
}
17+
/*font-family: 'Sedgwick Ave Display', cursive;
18+
font-family: 'Alegreya', serif;
19+
font-family: 'Alegreya Sans', sans-serif;*/
20+
.haberbaslik{
21+
font-family: 'Sedgwick Ave Display', cursive;
22+
font-size:35px;
23+
color:darkblue;
24+
}
25+
.habericerik{
26+
background-image:url("../img/defter.png");
27+
background-repeat: repeat;
28+
}
29+
.haberinfo{
30+
font-family: 'Alegreya Sans', sans-serif;
1531
}

Yonetim.UI.Web/Controllers/HaberController.cs

+49
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,54 @@ public ActionResult Ekle(HaberViewModel model)
5151
return View(model);
5252
}
5353
}
54+
public ActionResult Duzenle(int? id)
55+
{
56+
if (id == null)
57+
return RedirectToAction("Index");
58+
var haber = new HaberRepo().GetByID(id.Value);
59+
if (haber == null)
60+
return RedirectToAction("Index");
61+
var kategoriList = DropDownListDoldurucu.KategoriList();
62+
foreach (var item in kategoriList)
63+
{
64+
if (haber.Kategoriler.Select(x => x.Id).Contains(int.Parse(item.Value)))
65+
item.Selected = true;
66+
}
67+
ViewBag.Kategoriler = kategoriList.OrderByDescending(x => x.Selected);
68+
//ViewBag.Kategoriler = DropDownListDoldurucu.KategoriList();
69+
//ViewData["Kategoriler"]; üstekiyle aynı
70+
71+
var model = new HaberViewModel()
72+
{
73+
Icerik = haber.Icerik,
74+
Id = haber.Id,
75+
Kategoriler = haber.Kategoriler.Select(x => x.Id).ToList(),
76+
Baslik = haber.Baslik,
77+
Keywords = haber.Keywords,
78+
YayindaMi = haber.YayindaMi,
79+
EklenmeZamani = haber.EklenmeZamani
80+
};
81+
return View(model);
82+
}
83+
[HttpPost,ValidateInput(false)]
84+
public ActionResult Duzenle(HaberViewModel model)
85+
{
86+
ViewBag.Kategoriler = DropDownListDoldurucu.KategoriList();
87+
if(!ModelState.IsValid)
88+
{
89+
ModelState.AddModelError("", "Haber düzenlenirken bir hata oluştu");
90+
return View(model);
91+
}
92+
try
93+
{
94+
new HaberRepo().Update(model);
95+
return RedirectToAction("Index");
96+
}
97+
catch (Exception e)
98+
{
99+
ModelState.AddModelError("",e.Message);
100+
return View(model);
101+
}
102+
}
54103
}
55104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using Yonetim.BLL.Repository;
7+
using Yonetim.Model.ViewModels;
8+
9+
namespace Yonetim.UI.Web.Controllers
10+
{
11+
public class SiteController : Controller
12+
{
13+
// GET: Site
14+
public ActionResult Index()
15+
{
16+
var model = new HaberRepo().GetAll().Where(x => x.YayindaMi).Select(x => new HaberViewModel()
17+
{
18+
Id=x.Id,
19+
Baslik = x.Baslik,
20+
EklenmeZamani =x.EklenmeZamani,
21+
Hit =x.Hit,
22+
Icerik = x.Icerik,
23+
Keywords=x.Keywords
24+
}).ToList();
25+
return View(model);
26+
}
27+
public ActionResult Haber(int? id)
28+
{
29+
if (id == null) return RedirectToAction("Index");
30+
var haber = new HaberRepo().GetByID(id.Value);
31+
if (haber == null) return RedirectToAction("Index");
32+
haber.Hit++;
33+
new HaberRepo().Update();
34+
return View(haber);
35+
}
36+
}
37+
}
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@model HaberViewModel
2+
@{
3+
ViewBag.Title = $"{Model.Baslik} Haberini Düzenle";
4+
Layout = "~/Views/_AdminLayoutPage.cshtml";
5+
}
6+
<div class="row">
7+
<div class="col-lg-12">
8+
<h1 class="page-header">@($"{Model.Baslik} Haberini Düzenle")</h1>
9+
</div>
10+
</div>
11+
<div class="row">
12+
<div class="col-md-12">
13+
<div class="panel panel-primary">
14+
<div class="panel-heading">
15+
Haberler
16+
@Html.ValidationSummary()
17+
</div>
18+
<div class="panel-body">
19+
@using (Html.BeginForm("Duzenle", "Haber", FormMethod.Post, new { @class = "form-horizontal" }))
20+
{
21+
<div class="form-group">
22+
@Html.LabelFor(x => x.Baslik, new { @class = "col-sm-2 control-label" })
23+
<div class="col-sm-10">
24+
@Html.TextBoxFor(x => x.Baslik, new { @class = "form-control", placeholder = "Haber Başlığı" })
25+
@Html.ValidationMessageFor(x => x.Baslik)
26+
</div>
27+
</div>
28+
@Html.HiddenFor(x => x.Id)
29+
<div class="form-group">
30+
@Html.LabelFor(x => x.Kategoriler, new { @class = "col-sm-2 control-label" })
31+
<div class="col-sm-10">
32+
@Html.ListBoxFor(x => x.Kategoriler, ViewBag.Kategoriler as List<SelectListItem>, new { @class = "form-control", size = 7 })
33+
</div>
34+
</div>
35+
<div class="form-group">
36+
@Html.LabelFor(x => x.Icerik, new { @class = "col-sm-2 control-label" })
37+
<div class="col-sm-10">
38+
@Html.TextAreaFor(x => x.Icerik, new { @class = "form-control", placeholder = "İçerik" })
39+
</div>
40+
</div>
41+
<div class="form-group">
42+
@Html.LabelFor(x => x.YayindaMi, new { @class = "col-sm-2 control-label" })
43+
<div class="checkbox">
44+
<label class="col-sm-10">
45+
@Html.CheckBoxFor(x => x.YayindaMi)
46+
</label>
47+
</div>
48+
</div>
49+
<div class="form-group">
50+
@Html.LabelFor(x => x.Keywords, new { @class = "col-sm-2 control-label" })
51+
<div class="col-sm-10">
52+
@Html.TextBoxFor(x => x.Keywords, new { @class = "form-control", placeholder = "anahtar kelimeler" })
53+
</div>
54+
</div>
55+
<div class="form-group">
56+
<div class="col-sm-offset-2 col-sm-10">
57+
<button type="submit" class="btn btn-success btn-block">
58+
Haberi Güncelle
59+
</button>
60+
</div>
61+
</div>
62+
}
63+
</div>
64+
</div>
65+
</div>
66+
</div>
+22-31
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
@model HaberViewModel
22
@{
3-
ViewBag.Title = "Yeni Haber Ekle";
3+
ViewBag.Title = "Yeni Haber ekle";
44
Layout = "~/Views/_AdminLayoutPage.cshtml";
55
}
6-
76
<div class="row">
87
<div class="col-lg-12">
98
<h1 class="page-header">Yeni Haber Ekle</h1>
109
</div>
1110
</div>
1211
<div class="row">
13-
<div class="col-lg-8 col-md-offset-2">
12+
<div class="col-md-12">
1413
<div class="panel panel-primary">
1514
<div class="panel-heading">
1615
Haberler
@@ -26,39 +25,31 @@
2625
@Html.ValidationMessageFor(x => x.Baslik)
2726
</div>
2827
</div>
29-
<div class="form-group">
30-
@Html.LabelFor(x => x.Kategoriler, new { @class = "col-sm-2 control-label" })
31-
<div class="col-sm-10">
32-
@Html.ListBoxFor(x => x.Kategoriler, (List<SelectListItem>)ViewBag.Kategoriler, new { @class = "form-control", size = 7 })
33-
34-
</div>
28+
<div class="form-group">
29+
@Html.LabelFor(x => x.Kategoriler, new { @class = "col-sm-2 control-label" })
30+
<div class="col-sm-10">
31+
@Html.ListBoxFor(x => x.Kategoriler, (List<SelectListItem>)ViewBag.Kategoriler, new { @class = "form-control", size = 7 })
3532
</div>
36-
<div class="form-group">
37-
@Html.LabelFor(x => x.Icerik, new { @class = "col-sm-2 control-label" })
38-
<div class="col-sm-10">
39-
@Html.TextAreaFor(x => x.Icerik, new { @class = "form-control", placeholder = "İçerik" })
40-
</div>
33+
</div>
34+
<div class="form-group">
35+
@Html.LabelFor(x => x.Icerik, new { @class = "col-sm-2 control-label" })
36+
<div class="col-sm-10">
37+
@Html.TextAreaFor(x => x.Icerik, new { @class = "form-control", placeholder = "İçerik" })
4138
</div>
42-
<div class="form-group">
43-
@Html.LabelFor(x => x.Keywords, new { @class = "col-sm-2 control-label" })
44-
<div class="col-sm-10">
45-
@Html.TextBoxFor(x => x.Keywords, new { @class = "form-control", placeholder = "Anahtar Kelimeler" })
46-
</div>
39+
</div>
40+
<div class="form-group">
41+
@Html.LabelFor(x => x.Keywords, new { @class = "col-sm-2 control-label" })
42+
<div class="col-sm-10">
43+
@Html.TextBoxFor(x => x.Keywords, new { @class = "form-control", placeholder = "anahtar kelimeler" })
4744
</div>
48-
49-
<div class="form-group">
50-
51-
<div class="col-sm-offset-2 col-sm-10">
52-
<button type="submit" class="btn">Haberi Kaydet</button>
53-
</div>
45+
</div>
46+
<div class="form-group">
47+
<div class="col-sm-offset-2 col-sm-10">
48+
<button type="submit" class="btn btn-success btn-block">Haberi Kaydet</button>
5449
</div>
50+
</div>
5551
}
56-
57-
</div>
58-
<div class="panel-footer">
59-
Panel Footer
6052
</div>
6153
</div>
6254
</div>
63-
</div>
64-
55+
</div>

0 commit comments

Comments
 (0)