Janson's Stack reference
Tuesday, July 18, 2023
Sunday, July 10, 2022
MongoDb Query 2
Select necessary fields with skip and take
.AsQueryable().Where(p => p.EventId == eventId && titile.Content(p.Titile))
.Select(x => new CssGetVM
{
Id = x.Id,
EventId = x.EventId,
Title = x.Title,
Body = x.Body,
CustomBody=x.CustomBody,
InsertTimeStamp = x.InsertTimeStamp,
})
.Skip(0).Take(25)
.ToListAsync();
Join
Select Many
Where
- .Where(x => !restrictedEmails.Contains(x.Id))
- .Where(x => x.IsActive && x.Title.ToLower().Contains(title))
- .Where(x =>(!string.IsNullOrEmpty(x.Translations[nameof(x.Title)][languageCode]) && x.Translations[nameof(x.Title)][languageCode].ToLower().Contains(name))
||
(string.IsNullOrEmpty(x.Translations[nameof(x.Title)][languageCode]) && x.Title.ToLower().Contains(name))) - .Where(x => x.AccessDate.End >= DateTime.UtcNow).Where(x => x.AccessDate.Start <= DateTime.UtcNow)
- .OrderByDescending(x => x.InsertTimeStamp)
- .Where(x => x.Email == email.ToLowerInvariant())
- Query where inner array
where !user.IsDeleted && user.EventsConfigurations.Any(item => item.EventId == eventId && !item.IsDeleted) - _userCollection.AsQueryable().Where(user => user.EventsConfigurations.Any(item => item.EventId == eventId && !item.IsDeleted )). Where(item => !item.IsDeleted);
- normallizeNameQuery.OrderBy(x => x.LowerCaseFirstName)
.ThenBy(x => x.LowerCaseLastName)
.ThenByDescending(x => x.Date) - Where(x => x.EventsConfigurations.Any(x => eventIds.Contains(x.EventId) && !x.IsWorkspaceTeamMember)).Where(x => x.FirstName.Contains(searchDto.Search) ||x.LastName.Contains(searchDto.Search) ||x.Email.Contains(searchDto.Search) ||x.EventsConfigurations.Any(e => eventIds.Contains(e.EventId) && !e.IsDeleted&& e.PersonalInformation.JobTitle.Contains(searchDto.Search))).
Select
02) await query.Select(user => new UserResultViewModel
Utility
- ObjectId.GenerateNewId().ToString()
- public ObjectId Id { get; set; }
- [BsonElement("fn")] public string FirstName { get; set; }
Update
&
fb.ElemMatch(item => item.EventsConfigurations, e => e.EventId == eventId);
Bulk Update
two level nested element update
MOngosh
db['event-roles-permissions'].updateMany({RoleId:"62d65d092c3c5108e0975105"},{$set:{Name:"Booth Manager",Description:"Booth Manager Role"}})
Monday, May 30, 2022
MongoDb and C sharp
Base Repository
https://drive.google.com/file/d/1-2M7YotJQ1Q31XZB32l8nt70wbqnCE7t/view?usp=sharing
Tuesday, May 24, 2022
Mongo db query
Query
> use s27_events
- SELECT * FROM Profile
db.Profile.find ({}) - SELECT * FROM Profile WHERE Name = "Chamith"
db.Profile.find({Name:"Chamith"}) - SELECT * FROM Profile WHERE Name = "Chamith" AND Dob = "1988-01-24" AND Setting.Security._2fa = false
db.Profile.find({Name:"Chamith",Dob:"1988-01-24",Setting:{Security:{_2fa:false}}})
Update
update/add a new field to the collection
db.Profile.update({},{$set:{ProfileImage:"chamith.png"}})
db.Profile.update({},{$unset:{ProfileImage:"chamith.png"}})
db.Profile.update({},{$set:{ProfileImage:[{Url:"chamith1",IsDefault:false},{Url:"chamith2",IsDefault:true}]}})
db.Profile.update({},{$set:{Setting:{Security:{ _2fa:false}}}})
db.Profile.update({_id:ObjectId('628cae92a72e5e4316a8a8a5')},{$set:{Setting:{Preferences:{Country:"Sri Lanka",Currency:"LKR"},Security:{_2fa:true}}}})
Wednesday, February 24, 2021
Digital signature apply to http request body
public CheckValiedContent (HttpRequest request){
string xeroPrivateKey = Environment.GetEnvironmentVariable("XEROKEY");
var signatureHeader = request.Headers["x-xero-signature"];
var requestBody = request.Body;
var resultSignature = GenarateSignature(requestBody,xeroPrivateKey);
if (signatureHeader != resultSignature){
return 401
}
}
public string GenerateSignature(string dataToHash, string xeroKey)
{
using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(xeroKey)))
{
var messageBytes = Encoding.UTF8.GetBytes(dataToHash);
var hash = hmac.ComputeHash(messageBytes);
return Convert.ToBase64String(hash);
}
}
Wednesday, February 10, 2021
Backend best practices
Select praticulr coloms from database (EF)
https://git.itelasoft.com.au/chamith.saranga/broker-service/blob/master/Application/Services/BankStatementService.cs#L544
return await DataContext.BankStatements
.Where(s => bankStatementIds.Contains(s.RequestId))
.Include(s => s.Applicant).Include(s => s.Lender)
.Select(m => new BankStatementModel
{
RequestId = m.RequestId,
ApplicantId = m.ApplicantId,
ApplicantName = $"{m.Applicant.FirstName} {m.Applicant.LastName}",
IsPrimaryApplicant = m.Applicant.PrimaryApplicant,
LenderId = m.LenderId,
LenderName = m.Lender != null?m.Lender.Name : m.LenderName,
LenderLogo = m.Lender.Logo,
Deprecated = m.Deprecated,
Provider = m.Provider,
RequestVersion = m.RequestVersion
}).ToListAsync();
EF.Function
https://git.itelasoft.com.au/chamith.saranga/broker-service/blob/master/Application/Services/ProductService.cs#L134
if (!string.IsNullOrWhiteSpace(name))
query = query
.Where(p => EF.Functions.Like(p.Name, $@"%{name}%"));
-
Dapper - a simple object mapper for .Net https://github.com/StackExchange/dapper-dot-net/blob/master/Readme.md Install-Package Dappe...
-
csHtml file @{ ViewBag.Title = "Combobox"; } <h2>Combobox</h2> <div class="demo-section k-conten...
-
Using Custom Domains With IIS Express For Visual Studio 2015 the steps in the above answers apply but the applicationhost.config ...