public static UserDto CreateNewUser(NebulaDbContext dbContext, UserUpsertDto userToCreate, string loginName, Guid userGuid) { if (!userToCreate.RoleID.HasValue) { return(null); } var user = new User { UserGuid = userGuid, LoginName = loginName, Email = userToCreate.Email, FirstName = userToCreate.FirstName, LastName = userToCreate.LastName, IsActive = true, RoleID = userToCreate.RoleID.Value, CreateDate = DateTime.UtcNow, }; dbContext.User.Add(user); dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, user.UserID)); }
public static CustomRichTextDto GetByCustomRichTextTypeID(NebulaDbContext dbContext, int customRichTextTypeID) { var customRichText = dbContext.CustomRichText .SingleOrDefault(x => x.CustomRichTextTypeID == customRichTextTypeID); return(customRichText?.AsDto()); }
public static UserDto GetByUserGuid(NebulaDbContext dbContext, Guid userGuid) { var user = GetUserImpl(dbContext) .SingleOrDefault(x => x.UserGuid == userGuid); return(user?.AsDto()); }
public static RoleDto GetByRoleID(NebulaDbContext dbContext, int roleID) { var role = dbContext.Role .AsNoTracking() .FirstOrDefault(x => x.RoleID == roleID); return(role?.AsDto()); }
public static IEnumerable <RoleDto> List(NebulaDbContext dbContext) { var roles = dbContext.Role .AsNoTracking() .Select(x => x.AsDto()); return(roles); }
public static FieldDefinitionDto GetByFieldDefinitionTypeID(NebulaDbContext dbContext, int FieldDefinitionTypeID) { var fieldDefinition = dbContext.FieldDefinition .Include(x => x.FieldDefinitionType) .SingleOrDefault(x => x.FieldDefinitionTypeID == FieldDefinitionTypeID); return(fieldDefinition?.AsDto()); }
public static BoundingBoxDto GetBoundingBoxByWatershedIDs(NebulaDbContext dbContext, List <int> watershedIDs) { var watersheds = dbContext.Watershed .AsNoTracking() .Where(x => watershedIDs.Contains(x.WatershedID)); var geometries = watersheds.Select(x => x.WatershedGeometry4326).ToList(); return(new BoundingBoxDto(geometries)); }
public static IEnumerable <UserDto> ListByRole(NebulaDbContext dbContext, RoleEnum roleEnum) { var users = GetUserImpl(dbContext) .Where(x => x.IsActive && x.RoleID == (int)roleEnum) .OrderBy(x => x.FirstName).ThenBy(x => x.LastName) .Select(x => x.AsDto()) .AsEnumerable(); return(users); }
public static UserDto SetDisclaimerAcknowledgedDate(NebulaDbContext dbContext, int userID) { var user = dbContext.User.Single(x => x.UserID == userID); user.UpdateDate = DateTime.UtcNow; user.DisclaimerAcknowledgedDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, userID)); }
public static UserDto UpdateUserGuid(NebulaDbContext dbContext, int userID, Guid userGuid) { var user = dbContext.User .Single(x => x.UserID == userID); user.UserGuid = userGuid; user.UpdateDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, userID)); }
public static CustomRichTextDto UpdateCustomRichText(NebulaDbContext dbContext, int customRichTextTypeID, CustomRichTextDto customRichTextUpdateDto) { var customRichText = dbContext.CustomRichText .SingleOrDefault(x => x.CustomRichTextTypeID == customRichTextTypeID); // null check occurs in calling endpoint method. customRichText.CustomRichTextContent = customRichTextUpdateDto.CustomRichTextContent; dbContext.SaveChanges(); return(customRichText.AsDto()); }
public static FieldDefinitionDto UpdateFieldDefinition(NebulaDbContext dbContext, int FieldDefinitionTypeID, FieldDefinitionDto FieldDefinitionUpdateDto) { var fieldDefinition = dbContext.FieldDefinition .Include(x => x.FieldDefinitionType) .SingleOrDefault(x => x.FieldDefinitionTypeID == FieldDefinitionTypeID); // null check occurs in calling endpoint method. fieldDefinition.FieldDefinitionValue = FieldDefinitionUpdateDto.Definition; dbContext.SaveChanges(); return(fieldDefinition.AsDto()); }
public static List <ErrorMessage> ValidateUpdate(NebulaDbContext dbContext, UserUpsertDto userEditDto, int userID) { var result = new List <ErrorMessage>(); if (!userEditDto.RoleID.HasValue) { result.Add(new ErrorMessage() { Type = "Role ID", Message = "Role ID is required." }); } return(result); }
public static UserDto UpdateUserEntity(NebulaDbContext dbContext, int userID, UserUpsertDto userEditDto) { if (!userEditDto.RoleID.HasValue) { return(null); } var user = dbContext.User .Include(x => x.Role) .Single(x => x.UserID == userID); user.RoleID = userEditDto.RoleID.Value; user.ReceiveSupportEmails = userEditDto.RoleID.Value == 1 && userEditDto.ReceiveSupportEmails; user.UpdateDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, userID)); }
public static IEnumerable <UserDetailedDto> List(NebulaDbContext dbContext) { // right now we are assuming a parcel can only be associated to one user var parcels = dbContext.User.Include(x => x.Role).AsNoTracking().OrderBy(x => x.LastName).ThenBy(x => x.FirstName).ToList() .Select(user => { var userDetailedDto = new UserDetailedDto() { UserID = user.UserID, UserGuid = user.UserGuid, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, LoginName = user.LoginName, RoleID = user.RoleID, RoleDisplayName = user.Role.RoleDisplayName, Phone = user.Phone, ReceiveSupportEmails = user.ReceiveSupportEmails }; return(userDetailedDto); }).ToList(); return(parcels); }
public static List <WatershedDto> List(NebulaDbContext dbContext) { return(GetWatershedsImpl(dbContext).Select(x => x.AsDto()).ToList()); }
public static UserDto GetByEmail(NebulaDbContext dbContext, string email) { var user = GetUserImpl(dbContext).SingleOrDefault(x => x.Email == email); return(user?.AsDto()); }
private static IQueryable <Watershed> GetWatershedsImpl(NebulaDbContext dbContext) { return(dbContext.Watershed.AsNoTracking()); }
public static List <UserDto> GetByUserID(NebulaDbContext dbContext, List <int> userIDs) { return(GetUserImpl(dbContext).Where(x => userIDs.Contains(x.UserID)).Select(x => x.AsDto()).ToList()); }
public static UserDto GetByUserID(NebulaDbContext dbContext, int userID) { var user = GetUserImpl(dbContext).SingleOrDefault(x => x.UserID == userID); return(user?.AsDto()); }
public static IEnumerable <string> GetEmailAddressesForAdminsThatReceiveSupportEmails(NebulaDbContext dbContext) { var users = GetUserImpl(dbContext) .Where(x => x.IsActive && x.RoleID == (int)RoleEnum.Admin && x.ReceiveSupportEmails) .Select(x => x.Email) .AsEnumerable(); return(users); }
public static WatershedDto GetByWatershedID(NebulaDbContext dbContext, int watershedID) { return(GetWatershedsImpl(dbContext).SingleOrDefault(x => x.WatershedID == watershedID)?.AsDto()); }
public static List <WatershedDto> GetByWatershedID(NebulaDbContext dbContext, List <int> watershedIDs) { return(GetWatershedsImpl(dbContext).Where(x => watershedIDs.Contains(x.WatershedID)).Select(x => x.AsDto()).ToList()); }
public static List <FieldDefinitionDto> List(NebulaDbContext dbContext) { return(dbContext.FieldDefinition.Include(x => x.FieldDefinitionType).Select(x => x.AsDto()).ToList()); }
private static IQueryable <User> GetUserImpl(NebulaDbContext dbContext) { return(dbContext.User .Include(x => x.Role) .AsNoTracking()); }
public static FileResourceMimeType GetFileResourceMimeTypeByContentTypeName(NebulaDbContext dbContext, string contentTypeName) { return(dbContext.FileResourceMimeType.Single(x => x.FileResourceMimeTypeContentTypeName == contentTypeName)); }