Exemplo n.º 1
0
        private void CreateOrUpdateUpdateEvent(string updateDetails)
        {
            MemberUpdatedEvent?updatedEvent = Events.Find(evt => evt is MemberUpdatedEvent) as MemberUpdatedEvent;

            if (updatedEvent != null)
            {
                updatedEvent.UpdateDetails += "," + updateDetails;
                return;
            }

            updatedEvent = new MemberUpdatedEvent(this, updateDetails);
            Events.Add(updatedEvent);
        }
Exemplo n.º 2
0
        public void ReturnsProperMessageString()
        {
            Member member = MemberHelpers.CreateWithInternalConstructor();

            member.UpdateName("Steve", "Smith");

            MemberUpdatedEvent memberEvent = new MemberUpdatedEvent(member, "Links");

            var output   = DiscordLogMemberUpdateHandler.returnWebhookMessageString(memberEvent);
            var expected = $"User Steve Smith just updated their profile. Check it out here: https://devbetter.com/User/Details/TestUserId.";

            Assert.Equal(expected, output);
        }
Exemplo n.º 3
0
        public async Task <bool> HandleMember(MemberUpdatedMessage message)
        {
            MemberAggregate agg;

            if (message.Source == 0)
            {
                agg = _reader.ReadOneAsync(x => x.Member.ID == message.ID)?.Result ?? MemberAggregate.New();
            }
            else if (message.Source == 1)
            {
                agg = _reader.ReadOneAsync(x => x.Member.LegacyID == message.LegacyID)?.Result ?? MemberAggregate.New();
            }
            else
            {
                agg = MemberAggregate.New();
            }

            bool naoProcessa = agg != null;

            naoProcessa &= message.Version <= agg.Version;
            naoProcessa &= agg.HasEvent(x => x.LegacyID == message.LegacyID &&
                                        x.FullName == message.FullName &&
                                        x.ID == message.ID &&
                                        x.Age == message.Age &&
                                        x.CellNumber == message.CellNumber &&
                                        x.DateOfBirth == message.DateOfBirth);

            if (naoProcessa)
            {
                return(false);
            }

            try
            {
                var e = new MemberUpdatedEvent(message.ID, message.LegacyID, message.FullName, message.Age, message.CellNumber, message.DateOfBirth, message.RequestId, message.RequestDate);
                agg.AddEventToStream(e);
                agg.RebuildEventStream();
                agg.CommitChanges();
                Version = agg.Version;
                await _command.UpdateAsync(agg);
            }
            catch
            {
                //TODO: Implement retry policy
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public MemberUpdatedEvent CreateOrUpdateMember(IBasicRequestKey request, MemberUpdateDto dto,
                                                       Func <MemberUpdateDto, UserProfileDto> createUserProfileDto)
        {
            var member = MappingService.Map <Member>(dto).AsNewEntity();

            if (dto.Roles == null)
            {
                dto.Roles = new List <RoleDto>();
            }
            if (!dto.Roles.Any())
            {
                dto.Roles.Add(new RoleDto {
                    RoleType = RoleTypeName.BasicMember
                });
            }
            foreach (var roleDto in dto.Roles)
            {
                roleDto.UserKey = member.Key;
            }

            var roles = dto.Roles.Select(x => MappingService.Map <Role>(x).AsNewEntity()).ToList();

            var updatedEvent = new MemberUpdatedEvent().LinkTo(request);

            updatedEvent.WithProcessResult(ExecuteWithProcessResult(uow =>
            {
                var updatedMember = uow.Store.AddOrUpdate(member,
                                                          x => x.Email.Address == member.Email.Address ||
                                                          x.Mobile.LocalNumberWithAreaCodeInDigits == member.Mobile.LocalNumberWithAreaCodeInDigits ||
                                                          x.Username == member.Username
                                                          );
                var updatedMemberDto   = MappingService.Map <MemberUpdateDto>(updatedMember);
                updatedMemberDto.Roles = new List <RoleDto>();
                uow.Store.Delete <Role>(x => x.UserKey == updatedMember.Key);
                foreach (var role in roles)
                {
                    var updatedRole = uow.Store.Add(role);
                    updatedMemberDto.Roles.Add(MappingService.Map <RoleDto>(updatedRole));
                }
                updatedEvent.WithMember(updatedMemberDto)
                .WithUserProfile(createUserProfileDto?.Invoke(updatedMemberDto));
            }));
            return(updatedEvent);
        }