private static void AddUserMessageState(IDatabaseContext context, UserMessageStateEnum userMessageStateEnum, string name)
 {
     if (!context.UserMessageStates.Any(x => x.UserMessageStateEnum == userMessageStateEnum))
     {
         context.UserMessageStates.Add(new UserMessageState {
             Name = name, UserMessageStateEnum = userMessageStateEnum, CreationDate = DateTime.UtcNow, Version = 1
         });
     }
 }
示例#2
0
        public static UserMessage CreateValidUserMessage(
            Message message,
            User user,
            bool wasTransmitted = false,
            bool haveMention    = false,
            UserMessageCreationModeEnum modeEnum = UserMessageCreationModeEnum.ByObservedNew,
            UserMessageStateEnum stateEnum       = UserMessageStateEnum.Unreaded)
        {
            IUserMessageStateRepository        userMessageStateRepository        = ServiceLocator.Current.GetInstance <IUserMessageStateRepository>();
            IUserMessageCreationModeRepository userMessageCreationModeRepository = ServiceLocator.Current.GetInstance <IUserMessageCreationModeRepository>();

            return(new UserMessage
            {
                Id = Guid.NewGuid(),
                Message = message,
                User = user,
                UserMessageState = userMessageStateRepository.FindByEnum(stateEnum),
                WasTransmitted = wasTransmitted,
                HaveMention = haveMention,
                UserMessageCreationMode = userMessageCreationModeRepository.FindByEnum(modeEnum),
                SortingDate = DateTime.UtcNow
            });
        }
 public UserMessageState FindByEnum(UserMessageStateEnum userMessageStateEnum)
 {
     return(FindAll().FirstOrDefault(x => x.UserMessageStateEnum == userMessageStateEnum));
 }