Skip to content

Commit 68ffe6b

Browse files
author
Dhyan
committed
some fixes
1 parent b01d1a3 commit 68ffe6b

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

Bulky.DataAccess/Repository/Repository.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ public T Get(Expression<Func<T, bool>> filter, string? includeProperties = null,
4242
query = query.Where(filter);
4343
if (!string.IsNullOrEmpty(includeProperties))
4444
{
45-
foreach (var includeProp in includeProperties
46-
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
45+
foreach (var includeProperty in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
4746
{
48-
query = query.Include(includeProp);
47+
query = query.Include(includeProperty.Trim());
4948
}
5049
}
5150
return query.FirstOrDefault();

BulkyWeb/Areas/Admin/Controllers/UserController.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class UserController : Controller
1919

2020
private readonly IUnitOfWork _unitOfWork;
2121
private readonly UserManager<IdentityUser> _userManager;
22-
private readonly RoleManager<IdentityUser> _roleManager;
22+
private readonly RoleManager<IdentityRole> _roleManager;
2323

24-
public UserController(IUnitOfWork unitOfWork, UserManager<IdentityUser> userManager, RoleManager<IdentityUser> roleManager)
24+
public UserController(IUnitOfWork unitOfWork, UserManager<IdentityUser> userManager, RoleManager<IdentityRole> roleManager)
2525
{
2626
_userManager = userManager;
2727
_unitOfWork = unitOfWork;
@@ -38,9 +38,10 @@ public IActionResult RoleManagement(string userId)
3838
RoleManagementVM roleManagementVM = new()
3939
{
4040
ApplicationUser = _unitOfWork.ApplicationUserRepository.Get(u => u.Id == userId, includeProperties:"Company"),
41-
RoleList = _roleManager.Roles.Select(i => new SelectListItem{
41+
RoleList = _roleManager.Roles.Select(i => new SelectListItem
42+
{
4243
Text = i.Name,
43-
Value = i.Name.ToString(),
44+
Value = i.Name
4445
}),
4546
CompanyList = _unitOfWork.CompanyRepository.GetAll().Select(i => new SelectListItem
4647
{
@@ -61,11 +62,11 @@ public IActionResult RoleManagement(RoleManagementVM roleManagementVM)
6162

6263
string oldRole = _userManager.GetRolesAsync(_unitOfWork.ApplicationUserRepository.Get(u => u.Id == roleManagementVM.ApplicationUser.Id)).GetAwaiter().GetResult().FirstOrDefault();
6364

64-
65+
ApplicationUser applicationUser = _unitOfWork.ApplicationUserRepository.Get(u => u.Id == roleManagementVM.ApplicationUser.Id);
6566
if (roleManagementVM.ApplicationUser.Role != oldRole)
6667
{
6768
//Role is updated
68-
ApplicationUser applicationUser = _unitOfWork.ApplicationUserRepository.Get(u => u.Id == roleManagementVM.ApplicationUser.Id);
69+
6970
if(roleManagementVM.ApplicationUser.Role == SD.Role_Company)
7071
{
7172
applicationUser.CompanyId = roleManagementVM.ApplicationUser.CompanyId;
@@ -79,6 +80,14 @@ public IActionResult RoleManagement(RoleManagementVM roleManagementVM)
7980
_userManager.RemoveFromRoleAsync(applicationUser, oldRole).GetAwaiter().GetResult();
8081
_userManager.AddToRoleAsync(applicationUser, roleManagementVM.ApplicationUser.Role).GetAwaiter().GetResult() ;
8182
}
83+
else
84+
{
85+
if(oldRole == SD.Role_Company || roleManagementVM.ApplicationUser.CompanyId != applicationUser.CompanyId) {
86+
applicationUser.CompanyId = roleManagementVM.ApplicationUser.CompanyId;
87+
_unitOfWork.ApplicationUserRepository.Update(applicationUser);
88+
_unitOfWork.Save();
89+
}
90+
}
8291

8392
TempData["Success"] = "Role Updated.";
8493

@@ -93,15 +102,11 @@ public IActionResult RoleManagement(RoleManagementVM roleManagementVM)
93102
[HttpGet]
94103
public IActionResult GetAll()
95104
{
96-
List<ApplicationUser> userList = _db.ApplicationUsers.Include("Company").ToList();
97-
98-
var Roles = _db.Roles.ToList();
99-
var userRole = _db.UserRoles.ToList();
105+
List<ApplicationUser> userList = _unitOfWork.ApplicationUserRepository.GetAll(includeProperties: "Company").ToList();
100106

101107
foreach (var user in userList)
102108
{
103-
var roleId = userRole.FirstOrDefault(u => u.UserId == user.Id).RoleId;
104-
user.Role = Roles.FirstOrDefault(u => u.Id == roleId).Name;
109+
user.Role = _userManager.GetRolesAsync(user).GetAwaiter().GetResult().FirstOrDefault();
105110

106111
if(user.Company == null)
107112
{
@@ -117,7 +122,7 @@ public IActionResult GetAll()
117122
[HttpPost]
118123
public IActionResult LockUnlock([FromBody] string id)
119124
{
120-
var userObj = _db.ApplicationUsers.FirstOrDefault(u=> u.Id == id);
125+
var userObj = _unitOfWork.ApplicationUserRepository.Get(u=> u.Id == id);
121126
if (userObj == null)
122127
{
123128
return Json(new { success = false, message = "Error while locking/unlocking" });
@@ -131,7 +136,8 @@ public IActionResult LockUnlock([FromBody] string id)
131136
userObj.LockoutEnd = DateTime.Now.AddYears(1000);
132137
}
133138

134-
_db.SaveChanges();
139+
_unitOfWork.ApplicationUserRepository.Update(userObj);
140+
_unitOfWork.Save();
135141
return Json(new { success = true, message = "Opration successfully" });
136142
}
137143

BulkyWeb/Areas/Customer/Controllers/CartController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public IActionResult SummaryPOST()
169169
{
170170
//regulor customer user
171171
//add strip logic
172-
var domain = Request.Scheme + "//:" + Request.Host.Value + "/";
172+
var domain = Request.Scheme + "://" + Request.Host.Value + "/";
173173
var options = new SessionCreateOptions
174174
{
175175
SuccessUrl = domain + $"customer/cart/OrderConformation?id={shoppingCartVM.OrderHeader.Id}",

BulkyWeb/Areas/Customer/Controllers/HomeController.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ public IActionResult Index()
3030

3131
public IActionResult Details(int id)
3232
{
33-
ShoppingCart shoppingCart = new()
33+
ShoppingCart shoppingCart = new();
34+
if (shoppingCart.Product == null)
3435
{
35-
Product = _unitOfWork.ProductRepository.Get(u => u.Id == id, includeProperties: "Category,ProductImages"),
36-
Count = 1,
37-
ProductId = id
38-
};
36+
shoppingCart = new()
37+
{
38+
Product = _unitOfWork.ProductRepository.Get(u => u.Id == id, includeProperties: "ProductImages,Category"),
39+
Count = 1,
40+
ProductId = id
41+
};
42+
}
3943
return View(shoppingCart);
4044

4145
}

BulkyWeb/wwwroot/js/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function LoadDataTable() {
4141
</div>`
4242
}
4343
},
44-
"width": "25%"
44+
"width": "30%"
4545

4646
}
4747
]

0 commit comments

Comments
 (0)