Skip to content

Commit

Permalink
Merge pull request #8 from abdulrahmannadap/New-Update
Browse files Browse the repository at this point in the history
New update
  • Loading branch information
abdulrahmannadap authored Mar 8, 2024
2 parents 50ca39f + 27e536d commit bcc4ae0
Show file tree
Hide file tree
Showing 23 changed files with 1,924 additions and 762 deletions.
4 changes: 2 additions & 2 deletions FCommerce.DataAcsess/Repos/Implimentations/Repositoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public T Get(System.Linq.Expressions.Expression<Func<T, bool>> filter, string? i
IQueryable<T> query = _dbSet;
if (string.IsNullOrEmpty(includeProps))
{
foreach (var includeProp in includeProps.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
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);
query = query.Include(includeProp);
}
}

Expand Down
1 change: 1 addition & 0 deletions FCommerce.Models/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Product


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

Check warning on line 24 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")]
public int CategoryId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using FCommerce.Models;
using Microsoft.AspNetCore.Mvc;

namespace FCommerce.Website.Controllers
namespace FCommerce.Website.Areas.Admin.Controllers
{
[Area("Admin")]
public class CategorysController : Controller
{
#region Dependanceis
Expand Down Expand Up @@ -33,9 +34,9 @@ public IActionResult Upsert(int? id)
{
if (id == null || id == 0)
{
return View("UpsertForm",new Category());
return View("UpsertForm", new Category());
}
var editDataInDb = _unitOfWork.CategoryRepo.Get(c => c.Id == id);
var editDataInDb = _unitOfWork.CategoryRepo.Get(c => c.Id == id,"");

return View("UpsertForm", editDataInDb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace FCommerce.Website.Controllers
namespace FCommerce.Website.Areas.Admin.Controllers
{
[Area("Admin")]
public class ProductsController : Controller
{
#region Dependanceis
private readonly IUnitOfWork _unitOfWork;
private readonly INotyfService _notyfService;
private readonly IWebHostEnvironment _webHostEnvironment;

#endregion

#region Product Custructor
Expand Down Expand Up @@ -45,55 +46,52 @@ public IActionResult Upsert(int? id)

return View("UpsertForm", new Product());
}
var editDataInDb = _unitOfWork.ProductRepo.Get(c => c.Id == id);
var editDataInDb = _unitOfWork.ProductRepo.Get(c => c.Id == id,"Category");

//var editDataWithCategory = editDataInDb.CategoryId == id;

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

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

if (ModelState.IsValid)
{
if(file != null)
if (file != null)
{
//string fileExtensionName = Path.GetExtension(file.FileName);
string newFileName = "Image"+Guid.NewGuid().ToString().Substring(0,5)+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))
if (!string.IsNullOrEmpty(product.ImageUrl))
{
var oldImagePath = Path.Combine(webRootpath, product.ImageUrl.TrimStart('\\'));
if(System.IO.File.Exists(oldImagePath))
if (System.IO.File.Exists(oldImagePath))
{
System.IO.File.Delete(oldImagePath);
System.IO.File.Delete(oldImagePath);
}
}


//string finalDestination = webRootpath + @"\images\products";
string finalDestination = Path.Combine(webRootpath,@"images\products");
//Using Block Background Call Dispos Method
using (FileStream fileStream = new FileStream(Path.Combine(finalDestination,newFileName),FileMode.Create))
string finalDestination = Path.Combine(webRootpath , @"images\products");
//Using Block Background Call Dispos Method
using (FileStream fileStream = new FileStream(Path.Combine(finalDestination, newFileName), FileMode.Create))
{
file.CopyTo(fileStream);
}

//Reletive path
product.ImageUrl = @"\images\products\" + newFileName;
//product.ImageUrl = @"\images\products\" + newFileName;
product.ImageUrl = Path.Combine(@"\images\products\", newFileName);
}







if (product.Id == null || product.Id == 0)
if (product.Id == null || product.Id == 0)

Check warning on line 94 in FCommerce.Website/Areas/Admin/Controllers/ProductsController.cs

View workflow job for this annotation

GitHub Actions / build

The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
{
_unitOfWork.ProductRepo.Add(product);
_unitOfWork.Save();
Expand All @@ -102,7 +100,7 @@ public IActionResult Upsert(Product product,IFormFile? file)
else
{
_unitOfWork.ProductRepo.Edit(product);
_unitOfWork.Save();
_unitOfWork.Save();
_notyfService.Success("You have successfully Edit the data.");

}
Expand All @@ -128,7 +126,7 @@ public IActionResult Delete(int id)
_unitOfWork.Save();
_notyfService.Error("Product To Bee Deleted...");
}
return RedirectToAction("List");
return RedirectToAction("List", "Products");
}
//[HttpPost]
//public IActionResult DeleteConferm(int id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@


<div class="mb-3">
<a asp-controller="Categorys" asp-action="Upsert" class="btn btn-primary text-uppercase"><i class="bi bi-plus-lg"></i> Add More</a>
<a asp-area="Admin" asp-controller="Categorys" asp-action="Upsert" class="btn btn-primary text-uppercase"><i class="bi bi-plus-lg"></i> Add More</a>
</div>

<Table class="table table-hover table-bordered bg-warning ">
<thead>
<tr>
<th class="text-uppercase">Id </th>
<th class="text-uppercase">Name</th>
<th class="text-uppercase">Actions</th>
</tr>
Expand All @@ -36,10 +35,6 @@
@foreach(var categoryInModel in Model)
{
<tr>
<td>
@categoryInModel.Id
</td>

<td>
@categoryInModel.Name
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


<div class="m-2">
<a asp-action="List" asp-controller="categorys" class="btn btn-primary text-uppercase "><i class="bi bi-list-ol"></i> Go To list</a>
<a asp-area="Admin" asp-action="List" asp-controller="categorys" class="btn btn-primary text-uppercase "><i class="bi bi-list-ol"></i> Go To list</a>
</div>
<form asp-controller="Categorys" asp-action="Upsert" method="post" class="text-center mt-5">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<table class="table table-hover table-bordered bg-warning ">
<thead>
<tr>
<th>Id</th>
<th>Product Name</th>
<th>Product Description</th>
<th>Product Price</th>
Expand All @@ -32,7 +31,6 @@
@foreach(Product product in Model)
{
<tr>
<td>@product.Id</td>
<td>@product.ProductName</td>
<td>@product.Description</td>
<td>@product.ProductPrice</td>
Expand Down
72 changes: 72 additions & 0 deletions FCommerce.Website/Areas/Admin/Views/Products/UpsertForm.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@model Product

<div class="row">
<div class="col-8">
<div class="m-2">
<a asp-action="List" asp-controller="Products" class="btn btn-primary text-uppercase "><i class="bi bi-list-ol"></i> Go To list</a>
</div>
<form asp-area="Admin" asp-controller="Products" asp-action="Upsert" method="post" class="form-group text-center " enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>


<div>
<label class="col-form-label">Product Name</label>
<input type="text" asp-for="ProductName" placeholder="Enter Product name" class="form-control">
<span asp-validation-for="ProductName" class="text text-danger"></span>
</div>


<label class="col-form-label">Product Description</label>
<input type="text" asp-for="Description" placeholder="Enter Product name" class="form-control ">
<span asp-validation-for="Description" class="text text-danger"></span>


<div class="mt-2">
<label class="col-form-label">Product Price</label>
<input type="number" asp-for="ProductPrice" placeholder="Enter Product name" class="form-control">
<span asp-validation-for="ProductPrice" class="text text-danger"></span>
</div>
<div class="row mt-4">
<div class="col-3">
<label class=" fw-bold">select File</label>
</div>
<div class="col-9">
<input type="file" class="form-control" name="file" >
</div>
</div>

<div class="mt-2">
<select asp-for="CategoryId" asp-items="@ViewBag.CategoryItem" class="form-select">
<option selected disabled> Select Category</option>
</select>

</div>



<div class="mt-2">
<input type="submit" class="btn btn-success mt-3 text-uppercase mx-4 " value=@(Model.Id==0 ? "ADD" : "EDIT") />
<a asp-controller="Products" asp-action="List" class="btn btn-warning mt-3 text-uppercase">Cancelled</a>
</div>
</form>
</div>
<div class="col-4">
<div class="card">
<div class="card-header">

</div>
<div class="card-body">
<div class="card-img">
<img src="@Model.ImageUrl" height="300" width="300" alt="No Image Found"/>
</div>
</div>
</div>
</div>
</div>


@section Scripts {
@{
await Html.RenderPartialAsync("_ValidationScriptsPartial");
}
}
3 changes: 3 additions & 0 deletions FCommerce.Website/Areas/Admin/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using FCommerce.Website
@using FCommerce.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions FCommerce.Website/Areas/Admin/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace FCommerce.Website.Controllers
namespace FCommerce.Website.Areas.Customer.Controllers
{
[Area("Customer")]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions FCommerce.Website/Areas/Customer/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using FCommerce.Website
@using FCommerce.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions FCommerce.Website/Areas/Customer/Views/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
40 changes: 31 additions & 9 deletions FCommerce.Website/Configration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,39 @@ 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)
/// <param name="builder">builder</param>
public static void RegisterDependencies(WebApplicationBuilder builder)
{
// 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>();
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>();
}






//Old Wey To Set 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>();
//}
}
}
2 changes: 2 additions & 0 deletions FCommerce.Website/FCommerce.Website.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,6 +22,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="wwwroot\images\products\" />
</ItemGroup>

Expand Down
Loading

0 comments on commit bcc4ae0

Please sign in to comment.