Skip to content

Commit

Permalink
Merge pull request #7 from abdulrahmannadap/New-Update
Browse files Browse the repository at this point in the history
New update
  • Loading branch information
abdulrahmannadap authored Mar 7, 2024
2 parents 039b7da + c03018c commit 50ca39f
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 171 deletions.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProductPrice = table.Column<double>(type: "float", nullable: false),
ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: true),
CategoryId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
Expand Down
28 changes: 24 additions & 4 deletions FCommerce.DataAcsess/Repos/Implimentations/Repositoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,35 @@ public T Get(int id)
return _dbSet.Find(id);

Check warning on line 41 in FCommerce.DataAcsess/Repos/Implimentations/Repositoy.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

public T Get(System.Linq.Expressions.Expression<Func<T, bool>> filter)
public T Get(System.Linq.Expressions.Expression<Func<T, bool>> filter, string? includeProps = null)
{
return _dbSet.SingleOrDefault(filter);
IQueryable<T> query = _dbSet;
if (string.IsNullOrEmpty(includeProps))
{
foreach (var includeProp in includeProps.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))

Check warning on line 49 in FCommerce.DataAcsess/Repos/Implimentations/Repositoy.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
query = query.Include(includeProps);
}
}

return query.SingleOrDefault(filter);

Check warning on line 55 in FCommerce.DataAcsess/Repos/Implimentations/Repositoy.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}


public IEnumerable<T> GetAll()
public IEnumerable<T> GetAll(string? includeProps = null)
{
return _dbSet.ToList();
IQueryable<T> query = _dbSet;


if(!string.IsNullOrEmpty(includeProps))
{
foreach (var includeProp in includeProps.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(includeProps);
}
}

return query.ToList();
}
}
}
5 changes: 3 additions & 2 deletions FCommerce.DataAcsess/Repos/Interfaces/IRepositoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public interface IRepositoy<T> where T : class
void DeleteRange(IEnumerable<T> entities);
T Get(int id);

T Get(Expression<Func<T, bool>> filter);
IEnumerable<T> GetAll();
T Get(Expression<Func<T, bool>> filter, string? includeProps = null);

IEnumerable<T> GetAll(string? includeProps=null);

}
}
2 changes: 1 addition & 1 deletion FCommerce.Models/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Product
public string? ImageUrl { get; set; }


[ValidateNever]

[Required]
public Category Category { get; set; }

Check warning on line 23 in FCommerce.Models/Product.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Category' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[ForeignKey("Category")]
Expand Down
24 changes: 22 additions & 2 deletions FCommerce.Website/Configration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
namespace FCommerce.Website
using AspNetCoreHero.ToastNotification;
using FCommerce.DataAcsess;
using FCommerce.DataAcsess.Repos.UOWs;
using Microsoft.EntityFrameworkCore;

namespace FCommerce.Website
{
public class Configration
public static class Configration
{
/// <summary>
/// Register Your Dependencies
/// </summary>
/// <param name="services">builder.Services</param>
/// <param name="configuration">builder.ConfigurationS</param>
public static void RegisterDependencies(IServiceCollection services,IConfiguration configuration)
{
// Add services to the container.
services.AddDbContext<ApplicationDbContext>(option =>
{
option.UseSqlServer(configuration.GetConnectionString("DbConnection"));
});
services.AddNotyf(config => { config.DurationInSeconds = 10; config.IsDismissable = true; config.Position = NotyfPosition.BottomRight; });
services.AddScoped<IUnitOfWork, UnitOfWork>();
}
}
}
17 changes: 16 additions & 1 deletion FCommerce.Website/Controllers/CategorysController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ namespace FCommerce.Website.Controllers
{
public class CategorysController : Controller
{
#region Dependanceis
private readonly IUnitOfWork _unitOfWork;
private readonly INotyfService _notyfService;
#endregion

#region Category Constructor
public CategorysController(IUnitOfWork unitOfWork, INotyfService notyfService)
{
_unitOfWork = unitOfWork;
_notyfService = notyfService;
}
#endregion

#region Category List Method
public IActionResult List()
{

var categoryInDb = _unitOfWork.CategoryRepo.GetAll();
return View(categoryInDb);
}
#endregion

#region Category Upsert Get Method
public IActionResult Upsert(int? id)
{
if (id == null || id == 0)
Expand All @@ -31,6 +39,9 @@ public IActionResult Upsert(int? id)

return View("UpsertForm", editDataInDb);
}
#endregion

#region Category Upsert post Method
[HttpPost]
public IActionResult Upsert(Category category)
{
Expand All @@ -55,6 +66,9 @@ public IActionResult Upsert(Category category)
}
return NotFound();
}
#endregion

#region Category Delete Method

public IActionResult Delete(int id)
{
Expand All @@ -80,6 +94,7 @@ public IActionResult Delete(int id)
// _categoryRepo.Save();
// return RedirectToAction("List","Categorys");
//}
#endregion

}
}
18 changes: 15 additions & 3 deletions FCommerce.Website/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ProductsController(IUnitOfWork unitOfWork, INotyfService notyfService, IW
#region Product List
public IActionResult List()
{
var productInDb = _unitOfWork.ProductRepo.GetAllPro();
var productInDb = _unitOfWork.ProductRepo.GetAll("Category");
return View(productInDb);
}
#endregion
Expand All @@ -53,7 +53,7 @@ public IActionResult Upsert(int? id)

#region Product Upsert Post
[HttpPost]
public IActionResult Upsert(Product product,IFormFile file)
public IActionResult Upsert(Product product,IFormFile? file)
{

if (ModelState.IsValid)
Expand All @@ -63,6 +63,18 @@ public IActionResult Upsert(Product product,IFormFile file)
//string fileExtensionName = Path.GetExtension(file.FileName);
string newFileName = "Image"+Guid.NewGuid().ToString().Substring(0,5)+Path.GetExtension(file.FileName);
string webRootpath = _webHostEnvironment.WebRootPath;

// Edit method Of File Update
if(!string.IsNullOrEmpty(product.ImageUrl))
{
var oldImagePath = Path.Combine(webRootpath, product.ImageUrl.TrimStart('\\'));
if(System.IO.File.Exists(oldImagePath))
{
System.IO.File.Delete(oldImagePath);
}
}


//string finalDestination = webRootpath + @"\images\products";
string finalDestination = Path.Combine(webRootpath,@"images\products");
//Using Block Background Call Dispos Method
Expand All @@ -72,7 +84,7 @@ public IActionResult Upsert(Product product,IFormFile file)
}

//Reletive path
product.ImageUrl = @"\images\products" + newFileName;
product.ImageUrl = @"\images\products\" + newFileName;
}


Expand Down
15 changes: 9 additions & 6 deletions FCommerce.Website/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
using FCommerce.DataAcsess.Repos.Implimentations;
using FCommerce.DataAcsess.Repos.Interfaces;
using FCommerce.DataAcsess.Repos.UOWs;
using FCommerce.Website;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddDbContext<ApplicationDbContext>(option =>
{
option.UseSqlServer(builder.Configuration.GetConnectionString("DbConnection"));
});
builder.Services.AddNotyf(config => { config.DurationInSeconds = 10; config.IsDismissable = true; config.Position = NotyfPosition.BottomRight; });
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
Configration.RegisterDependencies(builder.Services,builder.Configuration) ;

//builder.Services.AddDbContext<ApplicationDbContext>(option =>
//{
// option.UseSqlServer(builder.Configuration.GetConnectionString("DbConnection"));
//});
//builder.Services.AddNotyf(config => { config.DurationInSeconds = 10; config.IsDismissable = true; config.Position = NotyfPosition.BottomRight; });
//builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
//builder.Services.AddScoped<ICategoryRepo, CategoryRepo>();
//builder.Services.AddScoped<IProductRepo, ProductRepo>();
var app = builder.Build();
Expand Down
9 changes: 3 additions & 6 deletions FCommerce.Website/Views/Categorys/List.cshtml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
@model IEnumerable<Category>

<div>
@* <div> New Toaster Massage
<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 Component.InvokeAsync("Notyf")
</div>
</div> *@


<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 Component.InvokeAsync("Notyf")
@* @if (TempData["Sucsess"] != null)
{
<div class="alert alert-success">
Expand Down
Loading

0 comments on commit 50ca39f

Please sign in to comment.