本文整理汇总了C#中IUserRepository.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.Where方法的具体用法?C# IUserRepository.Where怎么用?C# IUserRepository.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.Where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateLogin
public static void ValidateLogin(
User u,
string login,
IUserRepository users,
ModelStateDictionary state)
{
if (!String.IsNullOrEmpty(login) &&
(null == u || u.Login != login))
{
var same = users.Where(x => x.Login).Eq(login).List();
if (same.Rows.Length > 0 &&
(null == u || same.Rows.First().Id != u.Document.Id))
{
// there's already a user with this login address (besides the current one)
state.AddModelError("Login", "Login name already in use.");
}
}
}
示例2: ValidateEmail
public static void ValidateEmail(
User u,
string email,
IUserRepository users,
ModelStateDictionary state)
{
if (!String.IsNullOrEmpty(email) &&
(null == u || u.Email != email))
{
var same = users.Where(x => x.Email).Eq(email).List();
if (same.Rows.Length > 0 &&
(null == u || same.Rows.First().Id != u.Document.Id))
{
// there's already a user with this email address (besides the current one)
state.AddModelError("Email", "Email address already in use.");
}
}
}
示例3: UserModule
public UserModule(IBus bus, IAdvancedBus eBus, IUserRepository userRepository)
{
if (_defaultJsonMaxLength == 0)
_defaultJsonMaxLength = JsonSettings.MaxJsonLength;
//Hackeroonie - Required, due to complex model structures (Nancy default restriction length [102400])
JsonSettings.MaxJsonLength = Int32.MaxValue;
Get["/Users/All"] = _ => Response.AsJson(Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(userRepository));
Get["/Users"] = _ =>
{
var search = Context.Request.Query["search"];
var offset = Context.Request.Query["offset"];
var limit = Context.Request.Query["limit"];
if (offset == null) offset = 0;
if (limit == null) limit = 10;
var model = this.Bind<DataTablesViewModel>();
var dto = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(userRepository.Where(x => x.IsActive != false));//.Search(Context.Request.Query["search[value]"].Value, model.Start, model.Length));
return Negotiate
.WithView("Index")
.WithMediaRangeModel(MediaRange.FromString("application/json"), new { data = dto.ToList() });
};
Get["/UserLookup/{filter}"] = _ =>
{
var filter = (string)_.filter;
var dto = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(userRepository.Where(x => x.IsActive == true && (x.Individual.Name.StartsWith(filter) || x.Individual.Surname.StartsWith(filter))));
return Negotiate
.WithView("Index")
.WithMediaRangeModel(MediaRange.FromString("application/json"), new { dto });
};
Get["/UserCustomers/{userId:guid}"] = _ =>
{
var userId = (Guid)_.userId;
var customers = userRepository.Where(x => x.Id == userId && x.IsActive == true).SelectMany(x => x.CustomerUsers.Select(cu => cu.Customer));
return Negotiate
.WithView("Index")
.WithMediaRangeModel(MediaRange.FromString("application/json"), Mapper.Map<IEnumerable<Customer>, IEnumerable<CustomerDto>>(customers));
};
Get["/Userlist"] = parameters =>
{
var filter = "";
if (Context.Request.Query["q_word[]"].HasValue)
filter = (string)Context.Request.Query["q_word[]"].Value.ToString();
var pageIndex = 0;
var pageSize = 0;
int.TryParse(Context.Request.Query["page_num"].Value, out pageIndex);
int.TryParse(Context.Request.Query["per_page"].Value, out pageSize);
Expression<Func<User, bool>> predicate = x => x.IsActive == true && x.UserType == UserType.Internal && (x.Individual.Name.StartsWith(filter) || x.Individual.Surname.StartsWith(filter));
var users = new PagedList<User>(userRepository, pageIndex != 0 ? pageIndex - 1 : pageIndex, pageSize == 0 ? 10 : pageSize, predicate);
return Negotiate
.WithView("Index")
.WithMediaRangeModel(MediaRange.FromString("application/json"), new { result = Mapper.Map<IEnumerable<User>, IEnumerable<UserDto>>(users), cnt_whole = users.RecordsFiltered });
};
Get["/Users/Add"] = _ => View["Save", new UserDto()];
Get["/Users/{id:guid}"] = parameters =>
{
var guid = (Guid)parameters.id;
var dto = Mapper.Map<User, UserDto>(userRepository.Get(guid));
return View["Save", dto];
};
Get["/Users/Details/{id:guid}"] = parameters =>
{
var guid = (Guid)parameters.id;
var dto = Mapper.Map<User, UserDto>(userRepository.Get(guid));
return Response.AsJson(dto);
};
Post["/Users"] = _ =>
{
var dto = this.BindAndValidate<UserDto>();
dto.CreatedBy = Context.CurrentUser.UserName;
dto.IsActive = true;
if (dto.TrialExpiration == null) dto.TrialExpiration = DateTime.UtcNow.Date;
if (ModelValidationResult.IsValid)
{
//var clientUsersDto = this.Bind<List<ClientUserDto>>();
//dto.ClientUsers = clientUsersDto;
var entity = Mapper.Map(dto, userRepository.Get(dto.Id) ?? new User());
entity.HashPassword(dto.Password);
bus.Publish(new CreateUpdateEntity(entity, "Create"));
//.........这里部分代码省略.........