Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New update #8

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FCommerce.DataAcsess/Repos/Implimentations/Repositoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

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, string? includeProps = null)
Expand All @@ -46,13 +46,13 @@
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);
}
}

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.
}


Expand Down
1 change: 1 addition & 0 deletions FCommerce.Models/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
{
public int Id { get; set; }
[Required]
public string ProductName { get; set; }

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

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ProductName' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[Required]
public string Description { get; set; }

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

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[Required]
public double ProductPrice { get; set; }
[ValidateNever]
Expand All @@ -20,7 +20,8 @@


[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 @@
{
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 All @@ -47,7 +48,7 @@
{
if (ModelState.IsValid)
{
if (category.Id == null || category.Id == 0)

Check warning on line 51 in FCommerce.Website/Areas/Admin/Controllers/CategorysController.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.CategoryRepo.Add(category);
_unitOfWork.Save();
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 @@

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 @@
else
{
_unitOfWork.ProductRepo.Edit(product);
_unitOfWork.Save();
_unitOfWork.Save();
_notyfService.Success("You have successfully Edit the data.");

}
Expand All @@ -128,7 +126,7 @@
_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
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
Loading