Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public static CustomRichTextDto GetByCustomRichTextTypeID(NebulaDbContext dbContext, int customRichTextTypeID)
        {
            var customRichText = dbContext.CustomRichText
                                 .SingleOrDefault(x => x.CustomRichTextTypeID == customRichTextTypeID);

            return(customRichText?.AsDto());
        }
Exemplo n.º 3
0
        public static UserDto GetByUserGuid(NebulaDbContext dbContext, Guid userGuid)
        {
            var user = GetUserImpl(dbContext)
                       .SingleOrDefault(x => x.UserGuid == userGuid);

            return(user?.AsDto());
        }
Exemplo n.º 4
0
        public static RoleDto GetByRoleID(NebulaDbContext dbContext, int roleID)
        {
            var role = dbContext.Role
                       .AsNoTracking()
                       .FirstOrDefault(x => x.RoleID == roleID);

            return(role?.AsDto());
        }
Exemplo n.º 5
0
        public static IEnumerable <RoleDto> List(NebulaDbContext dbContext)
        {
            var roles = dbContext.Role
                        .AsNoTracking()
                        .Select(x => x.AsDto());

            return(roles);
        }
Exemplo n.º 6
0
        public static FieldDefinitionDto GetByFieldDefinitionTypeID(NebulaDbContext dbContext, int FieldDefinitionTypeID)
        {
            var fieldDefinition = dbContext.FieldDefinition
                                  .Include(x => x.FieldDefinitionType)
                                  .SingleOrDefault(x => x.FieldDefinitionTypeID == FieldDefinitionTypeID);

            return(fieldDefinition?.AsDto());
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 public static List <WatershedDto> List(NebulaDbContext dbContext)
 {
     return(GetWatershedsImpl(dbContext).Select(x => x.AsDto()).ToList());
 }
Exemplo n.º 17
0
        public static UserDto GetByEmail(NebulaDbContext dbContext, string email)
        {
            var user = GetUserImpl(dbContext).SingleOrDefault(x => x.Email == email);

            return(user?.AsDto());
        }
Exemplo n.º 18
0
 private static IQueryable <Watershed> GetWatershedsImpl(NebulaDbContext dbContext)
 {
     return(dbContext.Watershed.AsNoTracking());
 }
Exemplo n.º 19
0
 public static List <UserDto> GetByUserID(NebulaDbContext dbContext, List <int> userIDs)
 {
     return(GetUserImpl(dbContext).Where(x => userIDs.Contains(x.UserID)).Select(x => x.AsDto()).ToList());
 }
Exemplo n.º 20
0
        public static UserDto GetByUserID(NebulaDbContext dbContext, int userID)
        {
            var user = GetUserImpl(dbContext).SingleOrDefault(x => x.UserID == userID);

            return(user?.AsDto());
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
 public static WatershedDto GetByWatershedID(NebulaDbContext dbContext, int watershedID)
 {
     return(GetWatershedsImpl(dbContext).SingleOrDefault(x => x.WatershedID == watershedID)?.AsDto());
 }
Exemplo n.º 23
0
 public static List <WatershedDto> GetByWatershedID(NebulaDbContext dbContext, List <int> watershedIDs)
 {
     return(GetWatershedsImpl(dbContext).Where(x => watershedIDs.Contains(x.WatershedID)).Select(x => x.AsDto()).ToList());
 }
Exemplo n.º 24
0
 public static List <FieldDefinitionDto> List(NebulaDbContext dbContext)
 {
     return(dbContext.FieldDefinition.Include(x => x.FieldDefinitionType).Select(x => x.AsDto()).ToList());
 }
Exemplo n.º 25
0
 private static IQueryable <User> GetUserImpl(NebulaDbContext dbContext)
 {
     return(dbContext.User
            .Include(x => x.Role)
            .AsNoTracking());
 }
Exemplo n.º 26
0
 public static FileResourceMimeType GetFileResourceMimeTypeByContentTypeName(NebulaDbContext dbContext, string contentTypeName)
 {
     return(dbContext.FileResourceMimeType.Single(x => x.FileResourceMimeTypeContentTypeName == contentTypeName));
 }