mirror of
https://github.com/rudollee/LearningMVC.git
synced 2025-06-07 07:56:14 +00:00
56 lines
1.1 KiB
C#
56 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using SportsStore.Domain.Abstract;
|
|
using SportsStore.Domain.Entities;
|
|
|
|
namespace SportsStore.Domain.Concrete
|
|
{
|
|
public class EFProductRepository : IProductRepository
|
|
{
|
|
private EFDbContext context = new EFDbContext();
|
|
|
|
public IEnumerable<Product> Products
|
|
{
|
|
get { return context.Products; }
|
|
}
|
|
|
|
public void SaveProduct(Product product)
|
|
{
|
|
if (product.ProductID == 0)
|
|
{
|
|
context.Products.Add(product);
|
|
}
|
|
else
|
|
{
|
|
Product dbEntry = context.Products.Find(product.ProductID);
|
|
if (dbEntry != null)
|
|
{
|
|
dbEntry.Name = product.Name;
|
|
dbEntry.Description = product.Description;
|
|
dbEntry.Price = product.Price;
|
|
dbEntry.Category = product.Category;
|
|
dbEntry.ImageData = product.ImageData;
|
|
dbEntry.ImageMimeType = product.ImageMimeType;
|
|
}
|
|
}
|
|
|
|
context.SaveChanges();
|
|
}
|
|
|
|
public Product DeleteProduct(int productID)
|
|
{
|
|
Product dbEntry = context.Products.Find(productID);
|
|
if (dbEntry != null)
|
|
{
|
|
context.Products.Remove(dbEntry);
|
|
context.SaveChanges();
|
|
}
|
|
|
|
return dbEntry;
|
|
}
|
|
|
|
|
|
}
|
|
} |