示例#1
0
文件: User.cs 项目: sitkatech/nebula
        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));
        }
示例#2
0
        public static CustomRichTextDto GetByCustomRichTextTypeID(NebulaDbContext dbContext, int customRichTextTypeID)
        {
            var customRichText = dbContext.CustomRichText
                                 .SingleOrDefault(x => x.CustomRichTextTypeID == customRichTextTypeID);

            return(customRichText?.AsDto());
        }
示例#3
0
文件: User.cs 项目: sitkatech/nebula
        public static UserDto GetByUserGuid(NebulaDbContext dbContext, Guid userGuid)
        {
            var user = GetUserImpl(dbContext)
                       .SingleOrDefault(x => x.UserGuid == userGuid);

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

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

            return(roles);
        }
示例#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());
        }
示例#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));
        }
示例#8
0
文件: User.cs 项目: sitkatech/nebula
        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);
        }
示例#9
0
文件: User.cs 项目: sitkatech/nebula
        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));
        }
示例#10
0
文件: User.cs 项目: sitkatech/nebula
        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));
        }
示例#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());
        }
示例#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());
        }
示例#13
0
文件: User.cs 项目: sitkatech/nebula
        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);
        }
示例#14
0
文件: User.cs 项目: sitkatech/nebula
        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));
        }
示例#15
0
文件: User.cs 项目: sitkatech/nebula
        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);
        }
示例#16
0
 public static List <WatershedDto> List(NebulaDbContext dbContext)
 {
     return(GetWatershedsImpl(dbContext).Select(x => x.AsDto()).ToList());
 }
示例#17
0
文件: User.cs 项目: sitkatech/nebula
        public static UserDto GetByEmail(NebulaDbContext dbContext, string email)
        {
            var user = GetUserImpl(dbContext).SingleOrDefault(x => x.Email == email);

            return(user?.AsDto());
        }
示例#18
0
 private static IQueryable <Watershed> GetWatershedsImpl(NebulaDbContext dbContext)
 {
     return(dbContext.Watershed.AsNoTracking());
 }
示例#19
0
文件: User.cs 项目: sitkatech/nebula
 public static List <UserDto> GetByUserID(NebulaDbContext dbContext, List <int> userIDs)
 {
     return(GetUserImpl(dbContext).Where(x => userIDs.Contains(x.UserID)).Select(x => x.AsDto()).ToList());
 }
示例#20
0
文件: User.cs 项目: sitkatech/nebula
        public static UserDto GetByUserID(NebulaDbContext dbContext, int userID)
        {
            var user = GetUserImpl(dbContext).SingleOrDefault(x => x.UserID == userID);

            return(user?.AsDto());
        }
示例#21
0
文件: User.cs 项目: sitkatech/nebula
        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);
        }
示例#22
0
 public static WatershedDto GetByWatershedID(NebulaDbContext dbContext, int watershedID)
 {
     return(GetWatershedsImpl(dbContext).SingleOrDefault(x => x.WatershedID == watershedID)?.AsDto());
 }
示例#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());
 }
示例#24
0
 public static List <FieldDefinitionDto> List(NebulaDbContext dbContext)
 {
     return(dbContext.FieldDefinition.Include(x => x.FieldDefinitionType).Select(x => x.AsDto()).ToList());
 }
示例#25
0
文件: User.cs 项目: sitkatech/nebula
 private static IQueryable <User> GetUserImpl(NebulaDbContext dbContext)
 {
     return(dbContext.User
            .Include(x => x.Role)
            .AsNoTracking());
 }
示例#26
0
 public static FileResourceMimeType GetFileResourceMimeTypeByContentTypeName(NebulaDbContext dbContext, string contentTypeName)
 {
     return(dbContext.FileResourceMimeType.Single(x => x.FileResourceMimeTypeContentTypeName == contentTypeName));
 }