_vegabyte_
_vegabyte_
CC#
Created by _vegabyte_ on 1/24/2024 in #help
"Execution Timeout Expired. The timeout period elapsed prior to completion of the operation"
Im have a API to get all clients but the information need to fetch is needed some navigational properties. I use SingleQuery, SplitQuery and AsNoTracking. But I'm getting Execution Timeout Expired". Any suggestion and advice are well much appreciated! https://paste.mod.gg/otgeydlycylz/0
47 replies
CC#
Created by _vegabyte_ on 1/9/2024 in #help
Trying to create a notification service
No description
7 replies
CC#
Created by _vegabyte_ on 11/25/2023 in #help
Photo or File Uploading
Hi, i have some requirements for my app to upload files. What is the best way to implement this features. Local or Cloud? Amd what services. Your suggestions are much appreciated thanks!
6 replies
CC#
Created by _vegabyte_ on 11/22/2023 in #help
Proper way to access Navigational Properties
Hi, I trying to fetch data including the related data on other table. Is this the best way to to do it?
var regularClients = _context.Clients
.Include(mop => mop.ModeOfPayments)
.Include(abu => abu.AddedByUser)
.Include(rq => rq.Request)
.ThenInclude(user => user.Requestor)
.Include(rq => rq.Request)
.ThenInclude(ap => ap.Approvals)
.ThenInclude(cap => cap.Approver)
.Include(st => st.StoreType)
.Include(fd => fd.FixedDiscounts)
.Include(to => to.Term)
.ThenInclude(tt => tt.Terms)
.Include(to => to.Term)
.ThenInclude(td => td.TermDays)
.Include(ba => ba.BusinessAddress)
.Include(oa => oa.OwnersAddress)
.Include(bc => bc.BookingCoverages)
.Include(fr => fr.FreebiesRequests)
.ThenInclude(fi => fi.FreebieItems)
.ThenInclude(item => item.Items)
.ThenInclude(uom => uom.Uom)
.Include(lf => lf.ListingFees)
.ThenInclude(li => li.ListingFeeItems)
.ThenInclude(item => item.Item)
.ThenInclude(uom => uom.Uom)
.Include(cd => cd.ClientDocuments)
.AsNoTracking();
var regularClients = _context.Clients
.Include(mop => mop.ModeOfPayments)
.Include(abu => abu.AddedByUser)
.Include(rq => rq.Request)
.ThenInclude(user => user.Requestor)
.Include(rq => rq.Request)
.ThenInclude(ap => ap.Approvals)
.ThenInclude(cap => cap.Approver)
.Include(st => st.StoreType)
.Include(fd => fd.FixedDiscounts)
.Include(to => to.Term)
.ThenInclude(tt => tt.Terms)
.Include(to => to.Term)
.ThenInclude(td => td.TermDays)
.Include(ba => ba.BusinessAddress)
.Include(oa => oa.OwnersAddress)
.Include(bc => bc.BookingCoverages)
.Include(fr => fr.FreebiesRequests)
.ThenInclude(fi => fi.FreebieItems)
.ThenInclude(item => item.Items)
.ThenInclude(uom => uom.Uom)
.Include(lf => lf.ListingFees)
.ThenInclude(li => li.ListingFeeItems)
.ThenInclude(item => item.Item)
.ThenInclude(uom => uom.Uom)
.Include(cd => cd.ClientDocuments)
.AsNoTracking();
27 replies
CC#
Created by _vegabyte_ on 11/8/2023 in #help
✅ Proper implementation of API
Hi guys, so I have a client registration implementation. The client should input their Personal Information, Terms and Conditions, and add some valid documents. I divided them to 3 APIs, AddPersonalInfo, AddTermsAndCondition, AddAttachments. Since the informations is needed to provide all at once it means I will calling the API one by one, one after another. Do you guys think it's good practice? Or is there any another approach for this implementation. My concern is what if one of the API is failed, the saving should not be completed and be voided. Your suggestion are well appreciated. Thanks
15 replies
CC#
Created by _vegabyte_ on 10/27/2023 in #help
❔ Call API From Web API on Blazor Server
Hello respected community members, I am new to Blazor Server and I am currently trying to fetch data from a .NET Core Web API to populate a data table. I am struggling with getting the data and then displaying it in my Blazor component. I have an HttpClient service and I'm sending a GET request to my API endpoint. The API is working correctly. However, I am having trouble deserializing this JSON response and showing it in a table in my Blazor component. Here is the pertinent part of my code:
private readonly string _apiUrl = "http://localhost:5278/";

private GetAllApprovedProspectResult? prospects;

protected override async Task OnInitializedAsync()
{
await RefreshList();
}

private async Task RefreshList()
{
try
{
var request = new HttpRequestMessage(HttpMethod.Get,
_apiUrl + "api/Prospecting/GetAllApprovedProspect");

var client = ClientFactory.CreateClient();

var response = await client.SendAsync(request);

if (response.IsSuccessStatusCode)
{
using var responseStream = await response.Content.ReadAsStreamAsync();
prospects = await JsonSerializer.DeserializeAsync
<GetAllApprovedProspectResult>(responseStream);
}
else
{
getProspectError = true;
}

shouldRender = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private readonly string _apiUrl = "http://localhost:5278/";

private GetAllApprovedProspectResult? prospects;

protected override async Task OnInitializedAsync()
{
await RefreshList();
}

private async Task RefreshList()
{
try
{
var request = new HttpRequestMessage(HttpMethod.Get,
_apiUrl + "api/Prospecting/GetAllApprovedProspect");

var client = ClientFactory.CreateClient();

var response = await client.SendAsync(request);

if (response.IsSuccessStatusCode)
{
using var responseStream = await response.Content.ReadAsStreamAsync();
prospects = await JsonSerializer.DeserializeAsync
<GetAllApprovedProspectResult>(responseStream);
}
else
{
getProspectError = true;
}

shouldRender = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
31 replies
CC#
Created by _vegabyte_ on 9/21/2023 in #help
✅ Filtering problems in .Net Core
Hello everyone, I'm in the midst of a coding project and have encountered a challenge. I'm attempting to narrow down checklist questions by product type, but I'm encountering an issue with null product types. Even when I provide a productTypeId, I'm still getting checklist questions with null productTypeId. Any insights or suggestions would be highly valued. Your assistance is greatly appreciated! Thank you in advance!
22 replies
CC#
Created by _vegabyte_ on 8/15/2023 in #help
❔ Separation of .Net Core Web API and MVC in one soultion
HI, Is it possible to separate Web API and MVC projects? If yes how can I connect Web API to MVC? Any article and tutorials are much appreciated!
4 replies
CC#
Created by _vegabyte_ on 8/8/2023 in #help
✅ Multi Level of Approval
Hi, I recently create a system with approval level For Example: Sick Leave Request Module: 2 Approver Vacation Leave Request Module: 4 Approver The request will be forwarded to the first approver and after approved it will move to the second approver until the request is approved. But once the request is rejected, the request will be forwarded back to the requestor to review the request he made. He can re submit the request and start the process again. Condition: The level of approval is editable Any approver removed from the list of Approver that has pending for approval should retain the data and needs to be approved. It means any future request will be send to the new approver. It has also tracking to the timeline of the approval. When reject, when approved, who reject or who approved. Any suggestions on the database model to have different stages of approval in a Module. Any suggestion and advice is much appreciated. Thank you.
15 replies
CC#
Created by _vegabyte_ on 7/18/2023 in #help
❔ MediatR Issue with IRequest and Generic Method in ASP.NET Core
I'm facing an issue with MediatR in my ASP.NET Core project. I have an action method in a controller where I'm using MediatR's ISender.Send<TRequest> (where TRequest is GetCollectionsAsyncQuery) inside a generic method. However, I'm getting this exception: "The type 'GetCollectionsAsyncQuery' cannot be used as type parameter 'TRequest' in the generic type or method 'ISender.Send (TRequest, CancellationToken)'. There is no implicit reference conversion from 'GetCollectionsAsyncQuery' to 'IRequest'." Here's my HttpGet action method:
[HttpGet(Name = "GetCollectionAsync")]
public async Task<IActionResult> GetCollectionsAsync()
{
return await Handle<IEnumerable<GetCollectionsAsync.GetCollectionsAsyncQueryResult>>(
new GetCollectionsAsync.GetCollectionsAsyncQuery());
}
[HttpGet(Name = "GetCollectionAsync")]
public async Task<IActionResult> GetCollectionsAsync()
{
return await Handle<IEnumerable<GetCollectionsAsync.GetCollectionsAsyncQueryResult>>(
new GetCollectionsAsync.GetCollectionsAsyncQuery());
}
The relevant codes inside my Handler method and GetCollectionsAsyncQuery are:
public class GetCollectionsAsyncQuery : IRequest<IEnumerable<GetCollectionsAsyncQueryResult>> { }
//...
public class Handler : IRequestHandler<GetCollectionsAsyncQuery, IEnumerable<GetCollectionsAsyncQueryResult>>
{
var collections = await _context.Collections
.Include(group => group.Groups)
.ThenInclude(group => group.Payers)
.ThenInclude(payer => payer.Contributions)
.ToListAsync(cancellationToken);

if (collections == null) throw new NoCollectionFoundExceptions();
return _mapper.Map<IEnumerable<GetCollectionsAsyncQueryResult>>(collections);
}
public class GetCollectionsAsyncQuery : IRequest<IEnumerable<GetCollectionsAsyncQueryResult>> { }
//...
public class Handler : IRequestHandler<GetCollectionsAsyncQuery, IEnumerable<GetCollectionsAsyncQueryResult>>
{
var collections = await _context.Collections
.Include(group => group.Groups)
.ThenInclude(group => group.Payers)
.ThenInclude(payer => payer.Contributions)
.ToListAsync(cancellationToken);

if (collections == null) throw new NoCollectionFoundExceptions();
return _mapper.Map<IEnumerable<GetCollectionsAsyncQueryResult>>(collections);
}
42 replies
CC#
Created by _vegabyte_ on 7/14/2023 in #help
✅ JWT Authorization Issue with .NET Core Web API
Hello everyone, I am currently working on an ASP.NET Core Web API that uses JWT for authorization. I have a GetAllUsersAsync endpoint that needs to be authorized but I am facing some issues. Here is the code for the endpoint:
[HttpGet("GetAllUsers")]
[Authorize]
public async Task<IActionResult> GetAllUsersAsync([FromQuery] UserParams userParams)
{
// Implementation here...
}
[HttpGet("GetAllUsers")]
[Authorize]
public async Task<IActionResult> GetAllUsersAsync([FromQuery] UserParams userParams)
{
// Implementation here...
}
Here is my JWT authentication setup:
builder.Services.AddAuthentication(authOptions =>
{
authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
var key = builder.Configuration.GetValue<string>("JwtConfig:Key");
var keyBytes = Encoding.ASCII.GetBytes(key);

jwtOptions.SaveToken = true;
jwtOptions.RequireHttpsMetadata = false;
jwtOptions.TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(keyBytes),
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuer = false,
ClockSkew = TimeSpan.Zero,

ValidIssuer = builder.Configuration["JwtConfig:Issuer"],
ValidAudience = builder.Configuration["JwtConfig:Audience"]
};
});
builder.Services.AddAuthentication(authOptions =>
{
authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
var key = builder.Configuration.GetValue<string>("JwtConfig:Key");
var keyBytes = Encoding.ASCII.GetBytes(key);

jwtOptions.SaveToken = true;
jwtOptions.RequireHttpsMetadata = false;
jwtOptions.TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(keyBytes),
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuer = false,
ClockSkew = TimeSpan.Zero,

ValidIssuer = builder.Configuration["JwtConfig:Issuer"],
ValidAudience = builder.Configuration["JwtConfig:Audience"]
};
});
The problem I'm encountering is when I try to access the GetAllUsersAsync endpoint with a valid token, I still get unauthorized responses. It seems the token isn't correctly validated or there's something wrong with my setup. Would appreciate any ideas or suggestions on what might be wrong. Thank you in advance.
4 replies
CC#
Created by _vegabyte_ on 6/29/2023 in #help
❔ Best way on generating reports
Hi, what is the best way on generating reports? Stored Procs or LINQ?
5 replies
CC#
Created by _vegabyte_ on 6/25/2023 in #help
✅ Get an Id from a table and save it to other table
Hello, I have a Customer table that serves as a masterlist for my customers. I also have a Orders table. Now that the Orders table has a CustomerId column, it is referred to as the Customer table. Initially, I had a GetAllActiveCustomers api that will collect all the customers and match the customer's name from the incoming orders if they match, I will obtain the customerId and save it to the Orders table. Is there any other approach for this? Any suggestions would be greatly appreciated.
35 replies
CC#
Created by _vegabyte_ on 6/9/2023 in #help
❔ Need some advise regarding HTTP Request
Hello, I have a few operations here and would appreciate some guidance on how to carry them out. I therefore have a payer table. It has a column for the remaining balance. Additionally, I have a contribution table where the funds from payers go. I must update the Payer's remaining Balance if the payer adds a contribution (HTTP POST). Should I have to make two APIs? 1. Making a Contribution 2. Updating the balance that remains Or a single API that updates the remaining balance and create contributions?
38 replies
CC#
Created by _vegabyte_ on 6/7/2023 in #help
❔ Saving a JSON object to Database
HI. I want to save a Array to Database but I'm this error.
"Error getting value from 'Values' on 'ELIXIR.DATA.DATA_ACCESS_LAYER.MODELS.QC_CHECKLIST.CheckListString'.",
"Error getting value from 'Values' on 'ELIXIR.DATA.DATA_ACCESS_LAYER.MODELS.QC_CHECKLIST.CheckListString'.",
public class CheckListString
{
[Key]
public int ChecklistStringId { get; set; }
public int? PO_Summary_Id { get; set; }
public int? ReceivingId { get; set; }
public string Checlist_Type { get; set; }

[NotMapped]
public List<string> Values
{
get => JsonSerializer.Deserialize<List<string>>(Value);
set => Value = JsonSerializer.Serialize(value);
}
public string Value { get; set; }

public string Remarks { get; set; }
}
public class CheckListString
{
[Key]
public int ChecklistStringId { get; set; }
public int? PO_Summary_Id { get; set; }
public int? ReceivingId { get; set; }
public string Checlist_Type { get; set; }

[NotMapped]
public List<string> Values
{
get => JsonSerializer.Deserialize<List<string>>(Value);
set => Value = JsonSerializer.Serialize(value);
}
public string Value { get; set; }

public string Remarks { get; set; }
}
public async Task<bool> AddChecklists(Checklists input)
{
foreach (var checklistString in input.ChecklistsString)
{
var newChecklistString = new CheckListString
{
PO_Summary_Id = checklistString.PO_Summary_Id,
Checlist_Type = checklistString.Checlist_Type,
Values = checklistString.Values,
Remarks = checklistString.Remarks
};
await _context.CheckListStrings.AddAsync(newChecklistString);
}

await _context.SaveChangesAsync();

return true;
}
public async Task<bool> AddChecklists(Checklists input)
{
foreach (var checklistString in input.ChecklistsString)
{
var newChecklistString = new CheckListString
{
PO_Summary_Id = checklistString.PO_Summary_Id,
Checlist_Type = checklistString.Checlist_Type,
Values = checklistString.Values,
Remarks = checklistString.Remarks
};
await _context.CheckListStrings.AddAsync(newChecklistString);
}

await _context.SaveChangesAsync();

return true;
}
This is the body
{
"checklistsString": [
{
"checklistStringId": 0,
"pO_Summary_Id": 0,
"receivingId": 0,
"checlist_Type": "string",
"values": [
"string"
],
"value": "string",
"remarks": "string"
}
]
}
{
"checklistsString": [
{
"checklistStringId": 0,
"pO_Summary_Id": 0,
"receivingId": 0,
"checlist_Type": "string",
"values": [
"string"
],
"value": "string",
"remarks": "string"
}
]
}
Any help will be much appreciated
32 replies
CC#
Created by _vegabyte_ on 6/6/2023 in #help
❔ AutoMapper Mapping Profiles Configuration
Hello, I'm trying to obtain the "Groups" with the users included. I'm however experiencing various Auto Mapper-related issues. GetGroupsAsync
public class GetGroupsAsync
{
public class GroupsAsyncQuery : IRequest<IEnumerable<GroupsAsyncQueryResult>> {}

public class GroupsAsyncQueryResult
{
public Guid Id
{
get;
set;
}

public string GroupCode
{
get;
set;
}

public string GroupName
{
get;
set;
}
public IReadOnlyList<GetUsersAsync.UsersAsyncQueryResult> Users
{
get;
set;
}

}
public class Handler : IRequestHandler<GroupsAsyncQuery, IEnumerable<GroupsAsyncQueryResult>>
{
private readonly IMapper _mapper;
private readonly DataContext _dataContext;

public Handler(IMapper mapper, DataContext dataContext)
{
_mapper = mapper;
_dataContext = dataContext;
}

public async Task<IEnumerable<GroupsAsyncQueryResult>> Handle(GroupsAsyncQuery request,
CancellationToken cancellationToken)
{
var groups = await _dataContext.Groups
.Include(x => x.UsersCollection)
.ToListAsync(cancellationToken);
if (groups == null)
{
throw new NoGroupsFoundExceptions();
}

var result = _mapper.Map<IEnumerable<GroupsAsyncQueryResult>>(groups);
return result;
}
}

}
public class GetGroupsAsync
{
public class GroupsAsyncQuery : IRequest<IEnumerable<GroupsAsyncQueryResult>> {}

public class GroupsAsyncQueryResult
{
public Guid Id
{
get;
set;
}

public string GroupCode
{
get;
set;
}

public string GroupName
{
get;
set;
}
public IReadOnlyList<GetUsersAsync.UsersAsyncQueryResult> Users
{
get;
set;
}

}
public class Handler : IRequestHandler<GroupsAsyncQuery, IEnumerable<GroupsAsyncQueryResult>>
{
private readonly IMapper _mapper;
private readonly DataContext _dataContext;

public Handler(IMapper mapper, DataContext dataContext)
{
_mapper = mapper;
_dataContext = dataContext;
}

public async Task<IEnumerable<GroupsAsyncQueryResult>> Handle(GroupsAsyncQuery request,
CancellationToken cancellationToken)
{
var groups = await _dataContext.Groups
.Include(x => x.UsersCollection)
.ToListAsync(cancellationToken);
if (groups == null)
{
throw new NoGroupsFoundExceptions();
}

var result = _mapper.Map<IEnumerable<GroupsAsyncQueryResult>>(groups);
return result;
}
}

}
Any help we much appreciated. Thanks
43 replies
CC#
Created by _vegabyte_ on 6/3/2023 in #help
❔ WPF : Remove the Label in the Page
8 replies
CC#
Created by _vegabyte_ on 4/19/2023 in #help
❔ Catch all the exception
Hi, I'm trying to catch all the exceptions being thrown, Is that possible?
11 replies
CC#
Created by _vegabyte_ on 4/16/2023 in #help
❔ Querying Department Names using DepartmentID from User Queries
I'm attempting to query users based on their status, but I also want to display the department name associated with each user in the result. To accomplish this, I plan to use the department ID provided in the user query and perform a subsequent query to retrieve the associated department name. What approach would you recommend for achieving this?
public class GetUserByStatus
{
public class GetUserByStatusQuery : IRequest<IEnumerable<GetUserByStatusResult>>
{
public bool IsActive { get; set; }
}

public class GetUserByStatusResult
{
public int Id { get; set; }
public string FullName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool IsActive { get; set; }
public string DepartmentName { get; set; }
public string DateAdded { get; set; }
public string AddedBy { get; set; }
public string ModifiedBy { get; set; }
public string Reason { get; set; }
}

public class Handler : IRequestHandler<GetUserByStatusQuery, IEnumerable<GetUserByStatusResult>>
{
private readonly IServiceManager _serviceManager;
private readonly IMapper _mapper;

public Handler(IServiceManager serviceManager, IMapper mapper)
{
_serviceManager = serviceManager;
_mapper = mapper;
}

public async Task<IEnumerable<GetUserByStatusResult>> Handle(GetUserByStatusQuery request,
CancellationToken cancellationToken)
{
var user = await _serviceManager.User.GetUserByStatus(request.IsActive);
if (user == null)
throw new NoUserFoundException();

var result = _mapper.Map<IEnumerable<GetUserByStatusResult>>(user);
return result;
}
}
}
public class GetUserByStatus
{
public class GetUserByStatusQuery : IRequest<IEnumerable<GetUserByStatusResult>>
{
public bool IsActive { get; set; }
}

public class GetUserByStatusResult
{
public int Id { get; set; }
public string FullName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool IsActive { get; set; }
public string DepartmentName { get; set; }
public string DateAdded { get; set; }
public string AddedBy { get; set; }
public string ModifiedBy { get; set; }
public string Reason { get; set; }
}

public class Handler : IRequestHandler<GetUserByStatusQuery, IEnumerable<GetUserByStatusResult>>
{
private readonly IServiceManager _serviceManager;
private readonly IMapper _mapper;

public Handler(IServiceManager serviceManager, IMapper mapper)
{
_serviceManager = serviceManager;
_mapper = mapper;
}

public async Task<IEnumerable<GetUserByStatusResult>> Handle(GetUserByStatusQuery request,
CancellationToken cancellationToken)
{
var user = await _serviceManager.User.GetUserByStatus(request.IsActive);
if (user == null)
throw new NoUserFoundException();

var result = _mapper.Map<IEnumerable<GetUserByStatusResult>>(user);
return result;
}
}
}
29 replies