Exemple #1
0
        /// <summary>
        /// Record a user event
        /// </summary>
        /// <param name="userEvent">User Event to record</param>
        public void Create(UserEvent userEvent)
        {
            // Should be the current logged in user
            // We need to be able to override the created by user id field on the user events because we need the recording on masquerading implementation (at that point there is no Membership user id)
            var createdByUserId = userEvent.CreatedBy.GetValueOrDefault(AuditFieldsHelper.GetUserId());

            var userEventId = new StoredProcedures.Security.InsertUserEventMapper().Execute(userEvent, createdByUserId);
            
            // Make sure the record was created
            if (userEventId.HasValue == false)
            {
                throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30045, "UserEventDao.Create", additionalDescriptionParameters: (new object[] { userEvent.Reference })));
            }

            userEvent.Id = userEventId.Value;
        }
        public int? Execute(UserEvent userEvent, Guid createdByUserId)
        {
            // in parameters
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(Parameters.UserId, userEvent.UserId),
                DbHelper.CreateParameter(Parameters.UserEventTypeCode, userEvent.UserEventType.Code),
                DbHelper.CreateParameter(Parameters.Reference, userEvent.Reference),
                DbHelper.CreateParameter(Parameters.Notes, userEvent.Notes),
                DbHelper.CreateParameter(Parameters.CreatedByUserId, createdByUserId)
            };

            // out parameters
            SqlParameter id;
            parameters.Add(id = DbHelper.CreateParameterOut<int>(OutParameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand(this, parameters);

            // I've left the code compatible with the previous implementation, but I don't know if it's even possible that id would be null and the code would get here?
            return id.Value == DBNull.Value ? default(int?) : DbHelper.ParameterValue<int>(id);
        }
Exemple #3
0
        /// <summary>
        /// Create a user event with notes
        /// </summary>
        /// <param name="userName">user name to record event for</param>
        /// <param name="eventType">Event type based upon UserEventTypeCode</param>
        /// <param name="notes">notes</param>
        /// <param name="reference">Reference</param>
        public void RecordUserEvent(string userName, UserEventTypesEnum eventType, string notes = null, string reference = null)
        {
            MembershipUser user = null;

            if (string.IsNullOrEmpty(userName) == false)
            {
                user = Membership.GetUser(userName);
            }

            //Empty used for bad username case
            Guid? foundUserId = user != null ? (Guid?)user.ProviderUserKey : Guid.Empty;

            var userEvent = new UserEvent
            {
                UserId = foundUserId,
                UserEventType = new UserEventType { Code = eventType.GetCode() },
                Reference = reference ?? userName,
                Notes = notes,
            };

            userEventDao.Create(userEvent);
        }
Exemple #4
0
            public void CreateWithValidDataFillsIdIsSuccessful()
            {
                // Arrange
                var expectedUserEventType = UserEventTypesEnum.Login;
                DateTime expectedCreatedDate = DateTime.UtcNow;

                using (new TestDataHelper(string.Empty, GetTestQuery(TestQuery.CleanupUnitTestData)))
                {

                    var userEvent = new UserEvent
                    {
                        UserId = (Guid)validUser.ProviderUserKey,
                        UserEventType = new UserEventType { Code = expectedUserEventType.GetCode() },
                        Reference = VALIDUSERNAME,
                        Notes = VALIDNOTES
                    };

                    // Act
                    userEventDao.Create(userEvent);

                    // Assert
                    UserEvent userEventResult = userEventDao.GetByKey(userEvent.Id);

                    Assert.IsNotNull(userEvent.Id, "Id was not filled in after create");
                    Assert.AreEqual(expectedCreatedDate.Date, userEventResult.Created.Date);
                    Assert.AreEqual(expectedUserEventType, EnumExtensions.ParseEnumFromCode<UserEventTypesEnum>(userEventResult.UserEventType.Code));
                    Assert.AreEqual(TEST_USER_ID, userEventResult.CreatedBy);
                    Assert.AreEqual(VALIDUSERNAME, userEventResult.Reference);
                    Assert.AreEqual(VALIDNOTES, userEventResult.Notes);
                }
            }