Bulelani Botman
Bulelani Botman
Explore posts from servers
CC#
Created by Bulelani Botman on 3/19/2024 in #help
How Can I Pull 900K Records From My Database & Not Have The Page Slow Down When Rendering The Record
I have a project that is pulling 900K records from a database & displaying them to a view. Whenever I pull these records, I get a connection timeout error. I fixed that by pulling the top 50000 records, it works but then I have a problem that it takes time to fully display the page. I also have a problem that I'm displaying these records using DataTables & takes time to load the JavaScript. How can I fix this?
59 replies
CC#
Created by Bulelani Botman on 2/20/2024 in #help
Trying To Use The UserManager.IsInRoleAsync() Function In My Controller
I'm trying to retrieve different information based on a user who is login in but which what role? I am not getting anywhere, Visual Studio is saying I cannot convert from "System.Security.Claims.ClaimsPrincipal" to "Microsoft.AspNetCore.Identity.IdentityUser". Is there something I am missing?
namespace parentnchild.Controllers
{
public class InitialController : Controller
{
private readonly ApplicationDbContext _db;
private readonly UserManager<IdentityUser> _userManager;

public InitialController(ApplicationDbContext context, UserManager<IdentityUser> userManager)
{
_db = context;
_userManager = userManager;
}

/* GET METHOD */
/* This is the initial view in our flow of registering a property as a parent. It just displays the search input box without any other information on the page */
public IActionResult InitialView()
{

if (_userManager.IsInRoleAsync(User, "NORTH"))
{
List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("NORTH")).ToList();
return View(results);
}
else if (_userManager.IsInRoleAsync(User, "SOUTH"))
{

List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("SOUTH")).ToList();
return View(results);
}
else if (_userManager.IsInRoleAsync(User, "EAST"))
{

List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("EAST")).ToList();
return View(results);
}
else if (_userManager.IsInRoleAsync(User, "WEST"))
{

List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("WEST")).ToList();
return View(results);
}
else
{
List<LIS> results = _db.LIS.ToList();
return View(results);
}

}
}
namespace parentnchild.Controllers
{
public class InitialController : Controller
{
private readonly ApplicationDbContext _db;
private readonly UserManager<IdentityUser> _userManager;

public InitialController(ApplicationDbContext context, UserManager<IdentityUser> userManager)
{
_db = context;
_userManager = userManager;
}

/* GET METHOD */
/* This is the initial view in our flow of registering a property as a parent. It just displays the search input box without any other information on the page */
public IActionResult InitialView()
{

if (_userManager.IsInRoleAsync(User, "NORTH"))
{
List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("NORTH")).ToList();
return View(results);
}
else if (_userManager.IsInRoleAsync(User, "SOUTH"))
{

List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("SOUTH")).ToList();
return View(results);
}
else if (_userManager.IsInRoleAsync(User, "EAST"))
{

List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("EAST")).ToList();
return View(results);
}
else if (_userManager.IsInRoleAsync(User, "WEST"))
{

List<LIS> results = _db.LIS.Where(s => s.Sector.Contains("WEST")).ToList();
return View(results);
}
else
{
List<LIS> results = _db.LIS.ToList();
return View(results);
}

}
}
6 replies
CC#
Created by Bulelani Botman on 1/18/2024 in #help
I Keep On Getting An SQLException When Trying To Update My Database
I keep on getting an "SqlException: Cannot insert explicit value for identity column in table 'Loans' when IDENTITY_INSERT is set to OFF" even though I am not expliitlyl inserting a value on a identity column on the table. What I am using is using the ID from another table called Applicants & updating a column in Loans called ApplicantID with the ID from this table, I don't get this error. I am using ASP.NET Core MVC, I just got an internship & the company uses this framework & I've been trying to learn it on my own because this is the first time ever in my life touching C#. Please upgrade the appsettings.json to your configuration if you intend to download the solution and figure out what is wrong. I am also willing to explain every question about a function or class because I didn't document the code. Also I didn't push the migrations to the github page. https://github.com/inalelub/homeloan
33 replies