Skip to content

Commit

Permalink
ArticleRightSideBarWidgetOptions sınıfı yazıldı.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimhalilgunduz committed Jan 27, 2023
1 parent 1323ab2 commit f03a7a4
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 13 deletions.
8 changes: 7 additions & 1 deletion BloggerWay.Entities/ComplexTypes/FilterBy.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
namespace BloggerWay.Entities.ComplexTypes
using System.ComponentModel.DataAnnotations;

namespace BloggerWay.Entities.ComplexTypes
{
public enum FilterBy
{
[Display(Name = "Kategori")]
Category = 0,
[Display(Name = "Tarih")]
Date = 1,
[Display(Name = "Okunma Sayısı")]
ViewCount = 2,
[Display(Name = "Yorum Sayısı")]
CommentCount = 3
}
}
7 changes: 6 additions & 1 deletion BloggerWay.Entities/ComplexTypes/OrderBy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
namespace BloggerWay.Entities.ComplexTypes
using System.ComponentModel.DataAnnotations;

namespace BloggerWay.Entities.ComplexTypes
{
public enum OrderBy
{
[Display(Name = "Tarih")]
Date = 0,
[Display(Name = "Okunma Sayısı")]
ViewCount = 1,
[Display(Name = "Yorum Sayısı")]
CommentCount = 2
}
}
52 changes: 52 additions & 0 deletions BloggerWay.Entities/Concrete/ArticleRightSideBarWidgetOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using BloggerWay.Entities.ComplexTypes;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace BloggerWay.Entities.Concrete
{
public class ArticleRightSideBarWidgetOptions
{
[DisplayName("Widget Başlığı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[MaxLength(150, ErrorMessage = "{0} alanı en fazla {1} karakter olmalıdır.")]
[MinLength(5, ErrorMessage = "{0} alanı en az {1} karakter olmalıdır.")]
public string Header { get; set; }
[DisplayName("Makale Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[Range(0, 50, ErrorMessage = "{0} alanı en az {1}, en fazla {2} olmalıdır.")]
public int TakeSize { get; set; }
[DisplayName("Kategori")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int CategoryId { get; set; }
[DisplayName("Filtre Türü")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public FilterBy FilterBy { get; set; }
[DisplayName("Sıralama Türü")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public OrderBy OrderBy { get; set; }
[DisplayName("Sıralama Ölçütü")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public bool IsAscending { get; set; }
[DisplayName("Başlangıç Tarihi")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[DataType(DataType.Date, ErrorMessage = "{0} alanı tarih formatında olmalıdır.")]
public DateTime StartAt { get; set; }
[DisplayName("Bitiş Tarihi")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[DataType(DataType.Date, ErrorMessage = "{0} alanı tarih formatında olmalıdır.")]
public DateTime EndAt { get; set; }
[DisplayName("Maksimum Okunma Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MaxViewCount { get; set; }
[DisplayName("Minimum Okunma Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MinViewCount { get; set; }
[DisplayName("Maksimum Yorum Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MaxCommentCount { get; set; }
[DisplayName("Minimum Yorum Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MinCommentCount { get; set; }
}
}
56 changes: 54 additions & 2 deletions BloggerWay.MVC/Areas/Admin/Controllers/OptionsController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using BloggerWay.Entities.Concrete;
using AutoMapper;
using BloggerWay.Entities.Concrete;
using BloggerWay.MVC.Areas.Admin.Models;
using BloggerWay.Services.Abstract;
using BloggerWay.Shared.Utilities.Extensions.Helpers.Abstract;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NToastNotify;
using System.Threading.Tasks;

namespace BloggerWay.MVC.Areas.Admin.Controllers
{
Expand All @@ -18,13 +22,21 @@ public class OptionsController : Controller
private readonly IWritableOptions<WebsiteInfo> _websiteInfoWriter;
private readonly SmtpSettings _smtpSettings;
private readonly IWritableOptions<SmtpSettings> _smtpSettingsWriter;
private readonly ArticleRightSideBarWidgetOptions _articleRightSideBarWidgetOptions;
private readonly IWritableOptions<ArticleRightSideBarWidgetOptions> _articleRightSideBarWidgetOptionsWriter;
private readonly ICategoryService _categoryService;
private readonly IMapper _mapper;

public OptionsController(IOptionsSnapshot<AboutUsPageInfo> aboutUsPageInfo, IWritableOptions<AboutUsPageInfo> aboutUsPageInfoWriter, IToastNotification toastNotification, IOptionsSnapshot<WebsiteInfo> websiteInfo, IWritableOptions<WebsiteInfo> websiteInfoWriter, IOptionsSnapshot<SmtpSettings> smtpSettings, IWritableOptions<SmtpSettings> smtpSettingsWriter)
public OptionsController(IOptionsSnapshot<AboutUsPageInfo> aboutUsPageInfo, IWritableOptions<AboutUsPageInfo> aboutUsPageInfoWriter, IToastNotification toastNotification, IOptionsSnapshot<WebsiteInfo> websiteInfo, IWritableOptions<WebsiteInfo> websiteInfoWriter, IOptionsSnapshot<SmtpSettings> smtpSettings, IWritableOptions<SmtpSettings> smtpSettingsWriter, IOptionsSnapshot<ArticleRightSideBarWidgetOptions> articleRightSideBarWidgetOptions, IWritableOptions<ArticleRightSideBarWidgetOptions> articleRightSideBarWidgetOptionsWriter, ICategoryService categoryService, IMapper mapper)
{
_aboutUsPageInfoWriter = aboutUsPageInfoWriter;
_toastNotification = toastNotification;
_websiteInfoWriter = websiteInfoWriter;
_smtpSettingsWriter = smtpSettingsWriter;
_articleRightSideBarWidgetOptionsWriter = articleRightSideBarWidgetOptionsWriter;
_categoryService = categoryService;
_mapper = mapper;
_articleRightSideBarWidgetOptions = articleRightSideBarWidgetOptions.Value;
_smtpSettings = smtpSettings.Value;
_websiteInfo = websiteInfo.Value;
_aboutUsPageInfo = aboutUsPageInfo.Value;
Expand Down Expand Up @@ -112,5 +124,45 @@ public IActionResult EmailSettings(SmtpSettings smtpSettings)
}
return View(smtpSettings);
}
[HttpGet]
public async Task<IActionResult> ArticleRightSideBarWidgetSettings()
{
var categoriesResult = await _categoryService.GetAllByNonDeletedAndActiveAsync();
var articleRightSideBarWidgetOptionsViewModel =
_mapper.Map<ArticleRightSideBarWidgetOptionsViewModel>(_articleRightSideBarWidgetOptions);
articleRightSideBarWidgetOptionsViewModel.Categories = categoriesResult.Data.Categories;
return View(articleRightSideBarWidgetOptionsViewModel);
}
[HttpPost]
public async Task<IActionResult> ArticleRightSideBarWidgetSettings(ArticleRightSideBarWidgetOptionsViewModel articleRightSideBarWidgetOptionsViewModel)
{
var categoriesResult = await _categoryService.GetAllByNonDeletedAndActiveAsync();
articleRightSideBarWidgetOptionsViewModel.Categories = categoriesResult.Data.Categories;
if (ModelState.IsValid)
{
_articleRightSideBarWidgetOptionsWriter.Update(x =>
{
x.Header = articleRightSideBarWidgetOptionsViewModel.Header;
x.TakeSize = articleRightSideBarWidgetOptionsViewModel.TakeSize;
x.CategoryId = articleRightSideBarWidgetOptionsViewModel.CategoryId;
x.FilterBy = articleRightSideBarWidgetOptionsViewModel.FilterBy;
x.OrderBy = articleRightSideBarWidgetOptionsViewModel.OrderBy;
x.IsAscending = articleRightSideBarWidgetOptionsViewModel.IsAscending;
x.StartAt = articleRightSideBarWidgetOptionsViewModel.StartAt;
x.EndAt = articleRightSideBarWidgetOptionsViewModel.EndAt;
x.MaxViewCount = articleRightSideBarWidgetOptionsViewModel.MaxViewCount;
x.MinViewCount = articleRightSideBarWidgetOptionsViewModel.MinViewCount;
x.MaxCommentCount = articleRightSideBarWidgetOptionsViewModel.MaxCommentCount;
x.MinCommentCount = articleRightSideBarWidgetOptionsViewModel.MinCommentCount;
});
_toastNotification.AddSuccessToastMessage("Makale sayfalarınızın widget ayarları başarıyla güncellenmiştir.", new ToastrOptions
{
Title = "Başarılı İşlem!"
});
return View(articleRightSideBarWidgetOptionsViewModel);

}
return View(articleRightSideBarWidgetOptionsViewModel);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using BloggerWay.Entities.ComplexTypes;
using BloggerWay.Entities.Concrete;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace BloggerWay.MVC.Areas.Admin.Models
{
public class ArticleRightSideBarWidgetOptionsViewModel
{
[DisplayName("Widget Başlığı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[MaxLength(150, ErrorMessage = "{0} alanı en fazla {1} karakter olmalıdır.")]
[MinLength(5, ErrorMessage = "{0} alanı en az {1} karakter olmalıdır.")]
public string Header { get; set; }
[DisplayName("Makale Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[Range(0, 50, ErrorMessage = "{0} alanı en az {1}, en fazla {2} olmalıdır.")]
public int TakeSize { get; set; }
[DisplayName("Kategori")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int CategoryId { get; set; }
[DisplayName("Filtre Türü")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public FilterBy FilterBy { get; set; }
[DisplayName("Sıralama Türü")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public OrderBy OrderBy { get; set; }
[DisplayName("Sıralama Ölçütü")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public bool IsAscending { get; set; }
[DisplayName("Başlangıç Tarihi")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[DataType(DataType.Date, ErrorMessage = "{0} alanı tarih formatında olmalıdır.")]
public DateTime StartAt { get; set; }
[DisplayName("Bitiş Tarihi")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
[DataType(DataType.Date, ErrorMessage = "{0} alanı tarih formatında olmalıdır.")]
public DateTime EndAt { get; set; }
[DisplayName("Maksimum Okunma Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MaxViewCount { get; set; }
[DisplayName("Minimum Okunma Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MinViewCount { get; set; }
[DisplayName("Maksimum Yorum Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MaxCommentCount { get; set; }
[DisplayName("Minimum Yorum Sayısı")]
[Required(ErrorMessage = "{0} alanı zorunludur.")]
public int MinCommentCount { get; set; }
public IList<Category> Categories { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@using BloggerWay.Entities.ComplexTypes
@model BloggerWay.MVC.Areas.Admin.Models.ArticleRightSideBarWidgetOptionsViewModel

@{
Layout = "_Layout";
ViewBag.Title = "Makale Sayfaları için Widget Ayarları";

}
<div class="row">
<div class="col-lg-8 offset-lg-2">
<div class="card mt-1 mb-1">
<div class="card-header">
<h4 class="text-center"><span class="fas fa-edit"></span> Makale Sayfaları için Widget Ayarları</h4>
</div>
<div class="card-body">
<form asp-controller="Options" asp-action="ArticleRightSideBarWidgetSettings" method="post" id="form-articlerightsidebarwidgetsettings-update">
<div asp-validation-summary="All" class="text-danger" id="validation-summary"></div>
<div class="form-row">
<div class="form-group col-md-6">
<label asp-for="Header"></label>
<input class="form-control" asp-for="Header" placeholder="Lütfen, tercih ettiğiniz widget başlığını giriniz." />
<span class="text-danger" asp-validation-for="Header"></span>
</div>
<div class="form-group col-md-6">
<label asp-for="TakeSize"></label>
<input type="number" class="form-control" asp-for="TakeSize" />
<span class="text-danger" asp-validation-for="TakeSize"></span>
</div>
<div class="form-group col-md-6">
<label for="filterByList" asp-for="FilterBy"></label>
<select id="filterByList" class="form-control" asp-for="FilterBy" asp-items="Html.GetEnumSelectList<FilterBy>()">
<option></option>
</select>
<span asp-validation-for="FilterBy" class="text-danger"></span>
</div>
<div class="form-group col-md-6">
<label for="categoryList" asp-for="CategoryId"></label>
<select id="categoryList" class="form-control" asp-for="CategoryId" asp-items="@(new SelectList(Model.Categories,"Id","Name"))">
<option></option>
</select>
<span asp-validation-for="CategoryId" class="text-danger"></span>
</div>
<div class="form-group col-md-6">
<label for="orderByList" asp-for="OrderBy"></label>
<select id="orderByList" class="form-control" asp-for="OrderBy" asp-items="Html.GetEnumSelectList<OrderBy>()">
<option></option>
</select>
<span asp-validation-for="OrderBy" class="text-danger"></span>
</div>
<div class="form-group col-md-6">
<label for="isAscendingList" asp-for="IsAscending"></label>
<select id="isAscendingList" class="form-control" asp-for="IsAscending">
<option></option>
<option value="true">Artan</option>
<option value="false">Azalan</option>

</select>
<span asp-validation-for="IsAscending" class="text-danger"></span>
</div>
<div class="form-group col-md-6">
<label for="startAtDatePicker" asp-for="StartAt"></label>
<input type="text" id="startAtDatePicker" class="form-control" value="@Model.StartAt.ToShortDateString()" asp-for="StartAt" />
<span asp-validation-for="StartAt" class="text-danger"></span>
</div>
<div class="form-group col-md-6">
<label for="endAtDatePicker" asp-for="EndAt"></label>
<input type="text" id="endAtDatePicker" class="form-control" value="@Model.EndAt.ToShortDateString()" asp-for="EndAt" />
<span asp-validation-for="EndAt" class="text-danger"></span>
</div>
<div class="form-group col-md-6">
<label asp-for="MinViewCount"></label>
<input type="number" class="form-control" asp-for="MinViewCount" />
<span class="text-danger" asp-validation-for="MinViewCount"></span>
</div>
<div class="form-group col-md-6">
<label asp-for="MaxViewCount"></label>
<input type="number" class="form-control" asp-for="MaxViewCount" />
<span class="text-danger" asp-validation-for="MaxViewCount"></span>
</div>
<div class="form-group col-md-6">
<label asp-for="MinCommentCount"></label>
<input type="number" class="form-control" asp-for="MinCommentCount" />
<span class="text-danger" asp-validation-for="MinCommentCount"></span>
</div>
<div class="form-group col-md-6">
<label asp-for="MaxCommentCount"></label>
<input type="number" class="form-control" asp-for="MaxCommentCount" />
<span class="text-danger" asp-validation-for="MaxCommentCount"></span>
</div>
<div class="form-group col-md-6">
<button type="submit" class="btn btn-primary"><span class="fas fa-save"></span> Kaydet</button>
<a class="btn btn-danger" asp-area="Admin" asp-controller="Home" asp-action="Index"><span class="fas fa-times"></span> İptal</a>
</div>
</div>

</form>
</div>
</div>
</div>
</div>
@section Scripts
{
<script src="https://cdn.jsdelivr.net/npm/select2@@4.1.0-beta.1/dist/js/select2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous"></script>
<script src="~/AdminLTE/js/articleRightSideBarWidgetSettings.js" type="application/ecmascript"></script>
}
@section Styles
{
<link href="https://cdn.jsdelivr.net/npm/select2@@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/cupertino/jquery-ui.min.css" integrity="sha512-ug/p2fTnYRx/TfVgL8ejTWolaq93X+48/FLS9fKf7AiazbxHkSEENdzWkOxbjJO/X1grUPt9ERfBt21iLh2dxg==" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/cupertino/theme.min.css" integrity="sha512-adRIgePtMQgAVB+Mfkhl+Nyva/WllWlFzJyyhYCjznU3Di+Z4SsYi1Rqsep11PYLpUsW/SjE4NXUkIjabQJCOQ==" crossorigin="anonymous" />
<link href="~/AdminLTE/css/select2-bootstrap4.min.css" rel="stylesheet" />

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@
<div class="sb-nav-link-icon"><i class="fas fa-tools"></i></div>
Genel Ayarlar
</a><a class="nav-link" asp-area="Admin" asp-controller="Options" asp-action="EmailSettings">
<div class="sb-nav-link-icon"><i class="fas fa-at"></i></div>
E-Posta Ayarları
</a>
<div class="sb-nav-link-icon"><i class="fas fa-at"></i></div>
E-Posta Ayarları
</a>
<a class="nav-link" asp-area="Admin" asp-controller="Options" asp-action="ArticleRightSideBarWidgetSettings">
<div class="sb-nav-link-icon"><i class="fas fa-newspaper"></i></div>
Makale Sayfaları için Widget Ayarları
</a>
<a class="nav-link" asp-area="Admin" asp-controller="Options" asp-action="About">
<div class="sb-nav-link-icon"><i class="fas fa-address-card"></i></div>
Hakkımızda Sayfa İçerikleri
Expand Down
Loading

0 comments on commit f03a7a4

Please sign in to comment.