本文整理汇总了C#中IRepository.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.FirstOrDefault方法的具体用法?C# IRepository.FirstOrDefault怎么用?C# IRepository.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRepository
的用法示例。
在下文中一共展示了IRepository.FirstOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FinalBillingModule
public FinalBillingModule(IRepository<FinalBilling> finalBillingDBRepository, IRepository<UserMeta> userMetaRepository, IRepository<AccountMeta> accountMetaRepository,
ICacheProvider<FinalBilling> finalBillingCacheProvider)
{
this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString(), RoleType.Support.ToString() });
_finalBillingDBRepository = finalBillingDBRepository;
finalBillingRepository = finalBillingCacheProvider.CacheClient.GetAll();
var endDateFilter = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 25);
var startDateFilter = new DateTime(DateTime.UtcNow.Year, (DateTime.UtcNow.Month - 1), 26);
Before += async (ctx, ct) =>
{
this.Info(() => "Before Hook - FinalBilling");
await CheckCache(ct);
return null;
};
After += async (ctx, ct) => this.Info(() => "After Hook - FinalBilling");
Get["/FinalBilling/"] = _ =>
{
var finalBillingStartDateFilter = Request.Query["startDate"];
var finalBillingEndDateFilter = Request.Query["endDate"];
if (!finalBillingStartDateFilter.HasValue && !finalBillingEndDateFilter.HasValue) return Negotiate.WithView("Index");
if (finalBillingStartDateFilter.HasValue) startDateFilter = finalBillingStartDateFilter;
if (finalBillingEndDateFilter.HasValue) endDateFilter = finalBillingEndDateFilter;
endDateFilter = endDateFilter.AddHours(23).AddMinutes(59).AddSeconds(59);
var customerClientList = new List<FinalBillingDto>();
foreach (var transaction in finalBillingRepository)
{
var customerClientIndex = customerClientList.FindIndex(x => x.Id == transaction.CustomerId || x.Id == transaction.ClientId);
if (customerClientIndex > 0) continue;
var customerClient = new FinalBillingDto();
var userList = new List<User>();
var customerTransactions = finalBillingRepository.Where(x => x.CustomerId == transaction.CustomerId
&& (x.Created >= startDateFilter && x.Created <= endDateFilter)).DistinctBy(x => x.UserTransaction.TransactionId);
var customerPackages = customerTransactions.Where(x => x.CustomerId == transaction.CustomerId)
.Select(x => x.Package.PackageId).Distinct().Count();
var customerUsers = customerTransactions.Where(x => x.CustomerId == transaction.CustomerId).DistinctBy(x => x.User.UserId).Count();
var clientTransactions = finalBillingRepository.Where(x => x.ClientId == transaction.ClientId).DistinctBy(x => x.UserTransaction.TransactionId);
var clientPackagesTotal = clientTransactions.Where(x => x.ClientId == transaction.ClientId)
.Select(x => x.Package.PackageId).Distinct().Count();
var clientUsers = customerTransactions.Where(x => x.ClientId == transaction.ClientId).DistinctBy(x => x.User.UserId).Count();
// Customer
if (transaction.ClientId == new Guid())
{
customerClient = new FinalBillingDto
{
Id = transaction.CustomerId,
CustomerName = transaction.CustomerName,
Transactions = customerTransactions.Count(),
Products = customerPackages,
AccountMeta = accountMetaRepository.FirstOrDefault(x => x.AccountNumber == transaction.AccountNumber)
};
customerClient.Users = customerUsers;
}
// Client
if (transaction.CustomerId == new Guid())
{
customerClient = new FinalBillingDto
{
Id = transaction.ClientId,
CustomerName = transaction.ClientName,
Transactions = clientTransactions.Count(),
Products = clientPackagesTotal,
AccountMeta = accountMetaRepository.FirstOrDefault(x => x.AccountNumber == transaction.AccountNumber)
};
customerClient.Users = clientUsers;
}
if (customerClientIndex < 0 && customerClient.Transactions > 0) customerClientList.Add(customerClient);
}
return Negotiate
.WithView("Index")
.WithMediaRangeModel(MediaRange.FromString("application/json"), new { data = customerClientList });
};
Get["/FinalBilling/CustomerClient/{searchId}/Users"] = param =>
{
var stageBillingStartDateFilter = Request.Query["startDate"];
//.........这里部分代码省略.........
示例2: GetProfile
private Profile GetProfile(string username, bool isAnonymous, IRepository<Profile> profiles)
{
var profile = profiles
.FirstOrDefault(p =>
p.User.UserName == username
&& p.ApplicationName == ApplicationName
&& p.IsAnonymous == isAnonymous);
if (profile == null)
{
var membershipUser = UnitOfWork.Current.CreateRepository<User>()
.FirstOrDefault(p => p.UserName == username
&& p.ApplicationName == ApplicationName);
if (membershipUser == null)
throw new ProviderException("Profile cannot be created. There is no membership user");
profile = new Profile();
profile.IsAnonymous = isAnonymous;
profile.LastUpdatedDate = System.DateTime.Now;
profile.LastActivityDate = System.DateTime.Now;
profile.ApplicationName = this.ApplicationName;
profile.UserId = membershipUser.Id;
profiles.Insert(profile);
}
return profile;
}
示例3: PreBillingModule
public PreBillingModule(IRepository<PreBilling> preBillingDBRepository,
IRepository<AccountMeta> accountMetaRepository, IRepository<UserMeta> userMetaRepository, ICacheProvider<PreBilling> preBillingCacheProvider,
IReportApiClient reportApiClient)
{
this.RequiresAnyClaim(new[] { RoleType.Admin.ToString(), RoleType.ProductManager.ToString(), RoleType.Support.ToString() });
_preBillingDBRepository = preBillingDBRepository;
_preBillingRepository = preBillingCacheProvider.CacheClient.GetAll();
var endDateFilter = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 25);
var startDateFilter = new DateTime(DateTime.UtcNow.Year, (DateTime.UtcNow.Month - 1), 26);
Before += async (ctx, ct) =>
{
this.Info(() => "Before Hook - PreBilling");
await CheckCache(ct);
return null;
};
After += async (ctx, ct) => this.Info(() => "After Hook - PreBilling");
Get["/PreBilling/"] = _ =>
{
var preBillStartDateFilter = Request.Query["startDate"];
var preBillEndDateFilter = Request.Query["endDate"];
if (!preBillStartDateFilter.HasValue && !preBillEndDateFilter.HasValue) return Negotiate.WithView("Index");
if (preBillStartDateFilter.HasValue) startDateFilter = preBillStartDateFilter;
if (preBillEndDateFilter.HasValue) endDateFilter = preBillEndDateFilter;
endDateFilter = endDateFilter.AddHours(23).AddMinutes(59).AddSeconds(59);
var customerClientList = new List<PreBillingDto>();
foreach (var transaction in _preBillingRepository)
{
var customerClientIndex = customerClientList.FindIndex(x => x.Id == transaction.CustomerId || x.Id == transaction.ClientId);
if (customerClientIndex > 0) continue;
var customerClient = new PreBillingDto();
var customerTransactions = _preBillingRepository.Where(x => x.CustomerId == transaction.CustomerId
&& (x.Created >= startDateFilter && x.Created <= endDateFilter))
.DistinctBy(x => x.UserTransaction.TransactionId);
var customerPackages = customerTransactions.Where(x => x.CustomerId == transaction.CustomerId)
.Select(x => x.Package.PackageId).Distinct().Count();
var customerUsers = customerTransactions.Where(x => x.CustomerId == transaction.CustomerId).DistinctBy(x => x.User.UserId).Count();
var clientTransactions = _preBillingRepository.Where(x => x.ClientId == transaction.ClientId
&& (x.Created >= startDateFilter && x.Created <= endDateFilter))
.DistinctBy(x => x.UserTransaction.TransactionId);
var clientPackagesTotal = clientTransactions.Where(x => x.ClientId == transaction.ClientId)
.Select(x => x.Package.PackageId).Distinct().Count();
var clientUsers = customerTransactions.Where(x => x.ClientId == transaction.ClientId).DistinctBy(x => x.User.UserId).Count();
if (customerTransactions.Count() < 0 && clientTransactions.Count() < 0) continue;
// Customer
if (transaction.ClientId == new Guid())
{
customerClient = new PreBillingDto
{
Id = transaction.CustomerId,
CustomerName = transaction.CustomerName,
Transactions = customerTransactions.Count(),
Products = customerPackages,
AccountMeta = accountMetaRepository.FirstOrDefault(x => x.AccountNumber == transaction.AccountNumber),
};
customerClient.Users = customerUsers;
}
// Client
if (transaction.CustomerId == new Guid())
{
customerClient = new PreBillingDto
{
Id = transaction.ClientId,
CustomerName = transaction.ClientName,
Transactions = clientTransactions.Count(),
Products = clientPackagesTotal,
AccountMeta = accountMetaRepository.FirstOrDefault(x => x.AccountNumber == transaction.AccountNumber)
};
customerClient.Users = clientUsers;
}
if ((transaction.ClientId == new Guid()) && (transaction.CustomerId == new Guid())) continue;
if (customerClientIndex < 0 && customerClient.Transactions > 0) customerClientList.Add(customerClient);
}
return Negotiate
//.........这里部分代码省略.........