SQL veri tabanına verileri kaydetmiyor

mrcbyk5353

Hectopat
Katılım
7 Mart 2021
Mesajlar
66
Daha fazla  
Cinsiyet
Erkek
Merhaba,
Ben veri tabanıma kullanıcıdan aldığım verileri kaydetmek istiyorum ama kaydedemiyorum. Hata da vermiyor. Veri tabanından verileri çekip listeleyebiliyorum ama veri tabanına veri kaydedemiyorum. Yardım eder misiniz? Nasıl kaydetmesini sağlarım? Bütün kodları aşağıya koyacağım belki onlarda hata vardır biraz uzun oldu kusura bakmayın.
Model;

C#:
namespace EntityLayer.Concrate
{
    public class Scooter
    {
        [Key]
        public int ScooterID { get; set; }
        public string ScooterName { get; set; }
        public string Color { get; set; }
        public string EnginPower { get; set; }
        public string Image { get; set; }
        public string CreatedYear { get; set; }
        public string Capacity { get; set; }
        //public bool Status { get; set; }
        public List<Reservation> Reservations { get; set; }

    }
}

Controller ;
C#:
using BusinessLayer.Concrete;
using DataAccessLayer.EntityFramework;
using EntityLayer.Concrate;
using Microsoft.AspNetCore.Mvc;

namespace MyScooter.Areas.Admin
{
    [Area("Admin")]
    public class ScooterController : Controller
    {
        ScooterManager scooterManager = new ScooterManager(new EfScooterDal());
        public IActionResult Index()
        {
            var values = scooterManager.TGetList();
            return View(values);
        }
        [HttpGet]
        public IActionResult AddScooter()
        {
            return View();
        }
        [HttpPost]
        public IActionResult AddScooter(Scooter scooter)
        {
           
            scooterManager.TAdd(scooter);
            return RedirectToAction("Index");
        }
       
    }
}


ScooterManager;

C#:
namespace BusinessLayer.Concrete
{
    public class ScooterManager:IScooterService
    {
        IScooterDal _scooterDal;

        public ScooterManager(IScooterDal scooterDal)
        {
            _scooterDal = scooterDal;
        }

        public void TAdd(Scooter t)
        {
            _scooterDal.Insert(t);
        }

        public void TDelete(Scooter t)
        {
            _scooterDal.Delete(t);
        }

        public Scooter TGetById(int id)
        {
            throw new NotImplementedException();
        }

        public List<Scooter> TGetList()
        {
            return _scooterDal.GetList();
        }

        public void TUpdate(Scooter t)
        {
            _scooterDal.Update(t);
        }
    }
}


ScooterService;
C#:
namespace BusinessLayer.Abstract
{
    public interface IScooterService : IGenericService<Scooter>
    {
    }
}

IGenericService;
C#:
namespace BusinessLayer.Abstract
{
    public interface IGenericService<T>
    {
        void TAdd(T t);
        void TDelete(T t);
        void TUpdate(T t);
        List<T> TGetList();
        T TGetById(int id);
        //List<T> GetByFilter(Expression<Func<T, bool>> filter);
    }
}

EfScooterDal;
C#:
namespace DataAccessLayer.EntityFramework
{
    public class EfScooterDal : GenericRepository<Scooter>, IScooterDal
    {
    }
}

GenericRespository;

C#:
namespace DataAccessLayer.Repository
{
    public class GenericRepository<T> : IGenericDal<T> where T : class
    {
        public void Delete(T t)
        {
            using var c = new Context();
            c.Remove(t);
            c.SaveChanges();
        }

        public T GetById(int id)
        {
            using var c= new Context();
            return c.Set<T>().Find(id);
        }

        public List<T> GetList()
        {
            using var c = new Context();
            return c.Set<T>().ToList();
        }

        public List<T> GetListByFilter(Expression<Func<T, bool>> filter)
        {
            using var c = new Context();
            return c.Set<T>().Where(filter).ToList();
        }

        public void Insert(T t)
        {
            using var c = new Context();
            c.Add(t);
        }

        public void Update(T t)
        {
            using var c = new Context();
            c.Update(t);
        }
    }
}


IGenericDal;

C#:
namespace DataAccessLayer.Abstract
{
    public interface IGenericDal<T>
    {
        void Insert(T t);
        void Update(T t);
        void Delete(T t);
        List<T> GetList();
        T GetById(int id);
        List<T> GetListByFilter(Expression<Func<T, bool>> filter);

    }
}
 

Technopat Haberler

Geri
Yukarı