Exemple #1
0
        protected override async Task <ICommandResult> Handle(UpdateNotificationCommand command)
        {
            UpdateNotificationCommandResult commandResult = new UpdateNotificationCommandResult();
            var userModel           = _userRepository.GetByAltId(command.UserAltId);
            var userAdditionalModel = _feelUserAdditionalDetailRepository.GetByUserId(Convert.ToInt32(userModel.Id));

            if (Convert.ToBoolean(command.ShouldUpdate))
            {
                if (Convert.ToBoolean(command.IsMailOpt))
                {
                    if (userAdditionalModel == null)
                    {
                        userAdditionalModel = _feelUserAdditionalDetailRepository.Save(new FeelUserAdditionalDetail
                        {
                            UserId         = Convert.ToInt32(userModel.Id),
                            OptedForMailer = true,
                            IsEnabled      = true,
                            ModifiedBy     = command.UserAltId
                        });
                    }
                    else
                    {
                        if (!userAdditionalModel.OptedForMailer)
                        {
                            userAdditionalModel.OptedForMailer = true;
                            userAdditionalModel = _feelUserAdditionalDetailRepository.Save(userAdditionalModel);
                        }
                    }
                }
                else
                {
                    if (userAdditionalModel != null && userAdditionalModel.OptedForMailer)
                    {
                        userAdditionalModel.OptedForMailer = false;
                        userAdditionalModel = _feelUserAdditionalDetailRepository.Save(userAdditionalModel);
                    }
                }
            }
            if (userAdditionalModel == null)
            {
                commandResult.IsMailOpt = false;
            }
            else if (userAdditionalModel != null && userAdditionalModel.OptedForMailer)
            {
                commandResult.IsMailOpt = true;
            }
            else
            {
                commandResult.IsMailOpt = false;
            }

            return(commandResult);
        }
        protected override async Task <ICommandResult> Handle(UpdateUserCommand command)
        {
            UpdateUserCommandResult commandResult = new UpdateUserCommandResult();
            var userModel           = _userRepository.GetByAltId(command.UserProfile.AltId);
            var userAdditionalModel = _feelUserAdditionalDetailRepository.GetByUserId(Convert.ToInt32(userModel.Id));

            if (!string.IsNullOrEmpty(command.UserProfile.FirstName) && !string.IsNullOrEmpty(command.UserProfile.LastName))
            {
                var countryAltId = Guid.Empty;
                if (!string.IsNullOrEmpty(command.UserProfile.PhoneCode))
                {
                    countryAltId = new Guid(command.UserProfile.PhoneCode.Split("~")[1]);
                    command.UserProfile.PhoneCode = command.UserProfile.PhoneCode.Split("~")[0];
                }
                else
                {
                    command.UserProfile.PhoneCode = "";
                }
                if (ShouldUpdate(userModel, null, command.UserProfile))
                {
                    var country = new Contracts.DataModels.Country();
                    if (countryAltId != Guid.Empty)
                    {
                        country = _countryRepository.GetByAltId(countryAltId);
                    }
                    userModel.FirstName   = command.UserProfile.FirstName;
                    userModel.LastName    = command.UserProfile.LastName;
                    userModel.PhoneCode   = command.UserProfile.PhoneCode;
                    userModel.PhoneNumber = command.UserProfile.PhoneNumber;
                    userModel.CountryId   = country != null ? country.Id : null as int?;
                    _userRepository.Save(userModel);
                }

                if (userAdditionalModel == null)
                {
                    SaveUserAdditionalDetail(userModel, command.UserProfile);
                }
                else
                {
                    if (ShouldUpdate(null, userAdditionalModel, command.UserProfile))
                    {
                        var formattedDate = "";
                        if (!string.IsNullOrEmpty(command.UserProfile.DOB))
                        {
                            var splittedDate = command.UserProfile.DOB.Split("/");
                            formattedDate = splittedDate[2] + "-" + splittedDate[1] + "-" + splittedDate[0];
                        }
                        if (!string.IsNullOrEmpty(command.UserProfile.Gender))
                        {
                            userAdditionalModel.Gender = (Gender)Enum.Parse(typeof(Gender), command.UserProfile.Gender);
                        }

                        userAdditionalModel.BirthDate = formattedDate;
                        userAdditionalModel           = _feelUserAdditionalDetailRepository.Save(userAdditionalModel);
                    }
                }
            }
            var userProfileModel = GetUserProfile(userModel, userAdditionalModel);

            commandResult.UserProfile = userProfileModel;
            return(commandResult);
        }
Exemple #3
0
        protected override async Task Handle(RegisterUserCommand command)
        {
            IPDetail ipDetail = new FIL.Contracts.DataModels.IPDetail();

            var country = _countryRepository.GetByAltId(new Guid(command.PhoneCode.Split("~")[1]));
            var user    = new FIL.Contracts.DataModels.User
            {
                AltId          = Guid.NewGuid(),
                Email          = command.Email,
                Password       = command.PasswordHash,
                RolesId        = command.ChannelId == Channels.Feel ? 11 : 2, // TODO: XXX: Need a default
                CreatedBy      = command.ModifiedBy,
                CreatedUtc     = DateTime.UtcNow,
                UserName       = command.UserName,
                FirstName      = command.FirstName,
                LastName       = command.LastName,
                PhoneCode      = command.PhoneCode.Split("~")[0],
                PhoneNumber    = command.PhoneNumber,
                ChannelId      = command.ChannelId,
                SignUpMethodId = command.SignUpMethodId,
                IsEnabled      = true,
                IsRASVMailOPT  = command.IsMailOpt,
                CountryId      = country.Id
            };

            user.IPDetailId = user.IPDetailId == 0 ? null : user.IPDetailId;
            var userDetails = _userRepository.Save(user);

            if (command.ChannelId == Channels.Feel)
            {
                var feelUserAdditional = new FeelUserAdditionalDetail
                {
                    UserId         = Convert.ToInt32(userDetails.Id),
                    OptedForMailer = Convert.ToBoolean(command.IsMailOpt),
                    SocialLoginId  = null,
                    SignUpMethodId = Convert.ToInt32(command.SignUpMethodId),
                    IsEnabled      = true
                };
                _feelUserAdditionalDetailRepository.Save(feelUserAdditional);
            }
            try
            {
                if (command.ReferralId != null)
                {
                    var referral = _referralRepository.GetByAltId(Guid.Parse(command.ReferralId));
                    if (referral != null)
                    {
                        userDetails.ReferralId = referral.Id;
                    }
                }
                ipDetail = _saveIPProvider.SaveIp(command.Ip);
                if (ipDetail != null)
                {
                    userDetails.IPDetailId = ipDetail.Id;
                    _userRepository.Save(userDetails);
                }
            }
            catch
            {
                ipDetail = null;
            }
            if (command.SiteId == Site.RASVSite)
            {
                await _mediator.Publish(new Events.Event.HubSpot.VisitorInfoEvent(user));
            }
        }