mopak.okul 2.0.0

dotnet add package mopak.okul --version 2.0.0
                    
NuGet\Install-Package mopak.okul -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="mopak.okul" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="mopak.okul" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="mopak.okul" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add mopak.okul --version 2.0.0
                    
#r "nuget: mopak.okul, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package mopak.okul@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=mopak.okul&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=mopak.okul&version=2.0.0
                    
Install as a Cake Tool

mopak.okul - Okul Yönetim Sistemi NuGet Paketi

Bu paket, Entity Framework Core ve MySQL kullanarak basit bir okul yönetim sistemi oluşturmanızı sağlar. İçerisinde Öğrenci (Ogrenci), Öğretmen (Ogretmen) ve Ders (Ders) modelleri ile CRUD işlemleri hazır olarak gelir.


1. KURULUM

1.1 Paketi Yükleme

dotnet add package mopak.okul

1.2 appsettings.json (Bağlantı Dizesi)

{
  "ConnectionStrings": {
    "OkulConnection": "Server=localhost;database=okul2;User=root;Password="
  }
}

1.3 Program.cs (ASP.NET Core 9.0)

using mopak.okul.Data;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<VeritabaniBaglantisi>(options =>
    options.UseMySQL(builder.Configuration.GetConnectionString("OkulConnection")));

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

1.4 _ViewImports.cshtml (View'larda namespace kullanımı)

@using mopak.okul.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

2. MODELLER (Veritabanı Tabloları)

2.1 Ogrenci.cs (Öğrenci Modeli)

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace mopak.okul.Models
{
    public class Ogrenci
    {
        [Key]
        public int id { get; set; }

        [Required(ErrorMessage = "Ad Soyad boş olamaz")]
        [DisplayName("Ad Soyad")]
        public string adSoyad { get; set; }

        [Required(ErrorMessage = "Sınıf boş olamaz")]
        [DisplayName("Sınıf")]
        public string sinif { get; set; }

        [Required(ErrorMessage = "Yaş boş olamaz")]
        [DisplayName("Yaş")]
        [Range(10, 20, ErrorMessage = "Yaş 10-20 arasında olmalı.")]
        public int yas { get; set; }
    }
}

Özellikler:

  • id - Birincil anahtar (Primary Key)
  • adSoyad - Zorunlu alan, validasyon mesajı var
  • sinif - Zorunlu alan
  • yas - 10-20 arası değer alabilir

2.2 Ogretmen.cs (Öğretmen Modeli)

using System.ComponentModel.DataAnnotations;

namespace mopak.okul.Models
{
    public class Ogretmen
    {
        [Key]
        public int id { get; set; }
        public string adSoyad { get; set; }
        public string brans { get; set; }
    }
}

2.3 Ders.cs (Ders Modeli) - Örnek İlişki

using System.ComponentModel.DataAnnotations;

namespace mopak.okul.Models
{
    public class Ders
    {
        [Key]
        public int id { get; set; }
        public string dersAdi { get; set; }
        public int dersKredisi { get; set; }
        public List<Ogrenci> ogrenci { get; set; } // Bire-çok ilişki
    }
}

3. DbContext (Veritabanı Bağlantısı)

3.1 VeritabaniBaglantisi.cs

using Microsoft.EntityFrameworkCore;
using mopak.okul.Models;

namespace mopak.okul.Data
{
    public class VeritabaniBaglantisi : DbContext
    {
        public VeritabaniBaglantisi() { }
        public VeritabaniBaglantisi(DbContextOptions<VeritabaniBaglantisi> options) : base(options) { }

        protected override void OnConfiguring(DbContextOptionsBuilder option)
        {
            if (!option.IsConfigured)
                option.UseMySQL("Server=localhost;database=okul2;User=root;Password=");
        }

        public DbSet<Ogrenci> Ogrenciler { get; set; }
        public DbSet<Ogretmen> Ogretmenler { get; set; }
    }
}

Önemli: OnConfiguring metodu sadece DI (Dependency Injection) yoksa çalışır. Eğer Program.cs'den AddDbContext ile eklediyseniz, oradaki bağlantı dizesi kullanılır.


4. CONTROLLER'LAR (İş Mantığı)

4.1 OgrenciController.cs (TAM CRUD - Listele, Ekle, Düzenle, Detay, Sil)

using Microsoft.AspNetCore.Mvc;
using mopak.okul.Data;
using mopak.okul.Models;

namespace mopak.okul.Controllers
{
    public class OgrenciController : Controller
    {
        // Tüm öğrencileri listele (GET)
        public IActionResult Index()
        {
            using (var db = new VeritabaniBaglantisi())
            {
                var ogrenciler = db.Ogrenciler.ToList();
                return View(ogrenciler);
            }
        }

        // Ekleme sayfasını göster (GET)
        public IActionResult Create()
        {
            return View();
        }

        // Ekleme işlemini yap (POST)
        [HttpPost]
        public IActionResult Create(Ogrenci ogr)
        {
            if (ModelState.IsValid) // Validasyon kontrolü
            {
                using (var db = new VeritabaniBaglantisi())
                {
                    db.Ogrenciler.Add(ogr);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            return View();
        }

        // Silme onay sayfası (GET)
        public IActionResult Delete(int id)
        {
            using (var db = new VeritabaniBaglantisi())
            {
                var ogr = db.Ogrenciler.Find(id);
                return View(ogr);
            }
        }

        // Silme işlemini yap (POST)
        [HttpPost]
        public IActionResult Delete(Ogrenci ogr)
        {
            using (var db = new VeritabaniBaglantisi())
            {
                var silinecek = db.Ogrenciler.Find(ogr.id);
                db.Ogrenciler.Remove(silinecek);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        }

        // Detay sayfası (GET)
        public IActionResult Details(int id)
        {
            using (var db = new VeritabaniBaglantisi())
            {
                var ogrenci = db.Ogrenciler.Find(id);
                return View(ogrenci);
            }
        }

        // Düzenleme sayfasını göster (GET)
        public IActionResult Edit(int id)
        {
            using (var db = new VeritabaniBaglantisi())
            {
                var ogrenci = db.Ogrenciler.Find(id);
                return View(ogrenci);
            }
        }

        // Düzenleme işlemini yap (POST)
        [HttpPost]
        public IActionResult Edit(Ogrenci yeniOgrenci)
        {
            if (ModelState.IsValid)
            {
                using (var db = new VeritabaniBaglantisi())
                {
                    db.Update(yeniOgrenci);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            return View(yeniOgrenci);
        }
    }
}

CRUD Metotları: | Metot | HTTP | Açıklama | |-------|------|----------| | Index() | GET | Tüm kayıtları listeler | | Create() | GET | Ekleme formunu gösterir | | Create(Ogrenci) | POST | Veritabanına ekler | | Details(int id) | GET | Tek kaydı gösterir | | Edit(int id) | GET | Düzenleme formunu gösterir | | Edit(Ogrenci) | POST | Kaydı günceller | | Delete(int id) | GET | Silme onay sayfasını gösterir | | Delete(Ogrenci) | POST | Kaydı siler |

4.2 OgretmenController.cs (İskelet)

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace mopak.okul.Controllers
{
    public class OgretmenController : Controller
    {
        public ActionResult Index() { return View(); }
        public ActionResult Details(int id) { return View(); }
        public ActionResult Create() { return View(); }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(IFormCollection collection)
        {
            try { return RedirectToAction(nameof(Index)); }
            catch { return View(); }
        }

        public ActionResult Edit(int id) { return View(); }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try { return RedirectToAction(nameof(Index)); }
            catch { return View(); }
        }

        public ActionResult Delete(int id) { return View(); }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try { return RedirectToAction(nameof(Index)); }
            catch { return View(); }
        }
    }
}

4.3 HomeController.cs (Ana Sayfa)

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using mopak.okul.Models;

namespace mopak.okul.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index() { return View(); }
        public IActionResult Privacy() { return View(); }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel
            {
                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
            });
        }
    }
}

5. VIEW'LAR (HTML Sayfaları)

5.1 Index.cshtml (Listeleme Sayfası)

Views/Ogrenci/Index.cshtml

@model IEnumerable<mopak.okul.Models.Ogrenci>

@{
    ViewData["Title"] = "Index";
}

<h1>Öğrenciler</h1>
<p>
    <a asp-action="Create">Yeni Öğrenci Ekle</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>Ad Soyad</th>
            <th>Sınıf</th>
            <th>Yaş</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.adSoyad)</td>
                <td>@Html.DisplayFor(modelItem => item.sinif)</td>
                <td>@Html.DisplayFor(modelItem => item.yas)</td>
                <td>
                    <a asp-action="Edit" asp-route-id="@item.id">Düzenle</a> |
                    <a asp-action="Details" asp-route-id="@item.id">Detaylar</a> |
                    <a asp-action="Delete" asp-route-id="@item.id">Sil</a>
                </td>
            </tr>
        }
    </tbody>
</table>

5.2 Create.cshtml (Ekleme Formu)

Views/Ogrenci/Create.cshtml

@model mopak.okul.Models.Ogrenci

@{
    ViewData["Title"] = "Create";
}

<h1>Yeni Öğrenci Ekle</h1>
<h4>Öğrenci Bilgileri</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Create">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="adSoyad" class="control-label"></label>
                <input asp-for="adSoyad" class="form-control" />
                <span asp-validation-for="adSoyad" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="sinif" class="control-label"></label>
                <input asp-for="sinif" class="form-control" />
                <span asp-validation-for="sinif" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="yas" class="control-label"></label>
                <input asp-for="yas" class="form-control" />
                <span asp-validation-for="yas" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Create" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>
<div>
    <a asp-action="Index">Listeye Geri Dön</a>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

5.3 Edit.cshtml (Düzenleme Formu)

Views/Ogrenci/Edit.cshtml

@model mopak.okul.Models.Ogrenci

@{
    ViewData["Title"] = "Edit";
}

<h1>Edit</h1>
<h4>Ogrenci</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Edit">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <input type="hidden" asp-for="id" />
            <div class="form-group">
                <label asp-for="adSoyad" class="control-label"></label>
                <input asp-for="adSoyad" class="form-control" />
                <span asp-validation-for="adSoyad" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="sinif" class="control-label"></label>
                <input asp-for="sinif" class="form-control" />
                <span asp-validation-for="sinif" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="yas" class="control-label"></label>
                <input asp-for="yas" class="form-control" />
                <span asp-validation-for="yas" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>
<div>
    <a asp-action="Index">Back to List</a>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

5.4 Details.cshtml (Detay Sayfası)

Views/Ogrenci/Details.cshtml

@model mopak.okul.Models.Ogrenci

@{
    ViewData["Title"] = "Details";
}

<h1>Details</h1>
<div>
    <h4>Ogrenci</h4>
    <hr />
    <dl class="row">
        <dt class="col-sm-2">@Html.DisplayNameFor(model => model.adSoyad)</dt>
        <dd class="col-sm-10">@Html.DisplayFor(model => model.adSoyad)</dd>
        <dt class="col-sm-2">@Html.DisplayNameFor(model => model.sinif)</dt>
        <dd class="col-sm-10">@Html.DisplayFor(model => model.sinif)</dd>
        <dt class="col-sm-2">@Html.DisplayNameFor(model => model.yas)</dt>
        <dd class="col-sm-10">@Html.DisplayFor(model => model.yas)</dd>
    </dl>
</div>
<div>
    <a asp-action="Edit" asp-route-id="@Model?.id">Edit</a> |
    <a asp-action="Index">Back to List</a>
</div>

5.5 Delete.cshtml (Silme Onay Sayfası)

Views/Ogrenci/Delete.cshtml

@model mopak.okul.Models.Ogrenci

@{
    ViewData["Title"] = "Delete";
}

<h1>Delete</h1>
<h3>Silmek İstediğinize Emin misiniz?</h3>
<div>
    <h4>Ogrenci</h4>
    <hr />
    <dl class="row">
        <dt class="col-sm-2">@Html.DisplayNameFor(model => model.adSoyad)</dt>
        <dd class="col-sm-10">@Html.DisplayFor(model => model.adSoyad)</dd>
        <dt class="col-sm-2">@Html.DisplayNameFor(model => model.sinif)</dt>
        <dd class="col-sm-10">@Html.DisplayFor(model => model.sinif)</dd>
        <dt class="col-sm-2">@Html.DisplayNameFor(model => model.yas)</dt>
        <dd class="col-sm-10">@Html.DisplayFor(model => model.yas)</dd>
    </dl>
    <form asp-action="Delete">
        <input type="hidden" asp-for="id" />
        <input type="submit" value="Delete" class="btn btn-danger" /> |
        <a asp-action="Index">Back to List</a>
    </form>
</div>

5.6 _Layout.cshtml (Ana Şablon)

Views/Shared/_Layout.cshtml

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - WebApplication2_EF</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
            <div class="container-fluid">
                <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">WebApplication2_EF</a>
                <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                    <ul class="navbar-nav flex-grow-1">
                        <li class="nav-item">
                            <a class="nav-link text-dark" asp-controller="Home" asp-action="Index">Home</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" asp-controller="Home" asp-action="Privacy">Privacy</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>
    <div class="container">
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>
    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2026 - WebApplication2_EF - <a asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

5.7 _ViewStart.cshtml

Views/_ViewStart.cshtml

@{
    Layout = "_Layout";
}

6. VERİTABANI MIGRATION (Migration Oluşturma)

Paketi kullandıktan sonra kendi projenizde migration oluşturmanız gerekir:

# Migration oluştur
dotnet ef migrations add InitialCreate

# Veritabanını oluştur/güncelle
dotnet ef database update

Eğer dotnet ef komutu bulunamazsa:

dotnet tool install --global dotnet-ef

7. ADIM ADIM SIFIRDAN KURULUM

# 1. Proje oluştur
dotnet new mvc -n OkulProjem
cd OkulProjem

# 2. Paketi ekle
dotnet add package mopak.okul

# 3. appsettings.json düzenle (bağlantı dizesini ekle)

# 4. Program.cs düzenle (AddDbContext ekle)

# 5. Migration oluştur
dotnet ef migrations add InitialCreate
dotnet ef database update

# 6. View'ları ekle (yukarıdaki .cshtml dosyalarını Views/Ogrenci/ klasörüne kopyala)

# 7. Projeyi çalıştır
dotnet run

8. PAKETİ NUGET.ORG'A YÜKLEME

Site Üzerinden:

  1. https://www.nuget.org adresine git
  2. Oturum aç (Microsoft/Google hesabı)
  3. Sağ üst Upload butonuna tıkla
  4. mopak.okul\packages\mopak.okul.1.0.0.nupkg dosyasını seç
  5. Metadata'yı kontrol et ve Submit yap

Komut Satırından:

dotnet nuget push "mopak.okul\packages\mopak.okul.1.0.0.nupkg" --api-key API-KEYINIZ --source https://api.nuget.org/v3/index.json
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 207 6/11/2026
1.0.0 117 6/11/2026