Esempio n. 1
0
 public FIL.Contracts.DataModels.Referral GetReferral(
     string referralId,
     long eventId,
     Guid modifiedBy
     )
 {
     try
     {
         var Referral = _referralRepository.GetBySlug(referralId);
         if (Referral != null)
         {
             return Referral;
         }
         else
         {
             var referral = new Referral
             {
                 Name = referralId,
                 Code = referralId,
                 Description = "",
                 AltId = Guid.NewGuid(),
                 EventId = eventId,
                 IsEnabled = true,
                 Slug = referralId,
                 CreatedBy = modifiedBy,
                 CreatedUtc = DateTime.UtcNow,
                 ModifiedBy = modifiedBy,
                 UpdatedBy = modifiedBy,
                 UpdatedUtc = DateTime.UtcNow
             };
             return _referralRepository.Save(referral);
         }
     }
     catch (Exception e)
     {
         _logger.Log(Logging.Enums.LogCategory.Error, e);
         return new Referral
         {
         };
     }
 }
        protected override async Task Handle(RasvRegisterUserCommand command)
        {
            IPDetail ipDetail     = new FIL.Contracts.DataModels.IPDetail();
            bool     shouldInsert = true;

            //For Facebook login in FAP
            if (command.ChannelId == Channels.Feel && !string.IsNullOrEmpty(command.SocialLoginId))
            {
                var userModel = _userRepository.GetByEmailAndChannel(command.Email, command.ChannelId, command.SignUpMethodId);
                if (userModel != null)
                {
                    shouldInsert            = false;
                    userModel.SocialLoginId = command.SocialLoginId;
                    _userRepository.Save(userModel);
                }
            }
            if (shouldInsert)
            {
                var user = new 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,
                    PhoneNumber    = command.PhoneNumber,
                    ChannelId      = command.ChannelId,
                    IsActivated    = true,
                    SignUpMethodId = command.SignUpMethodId,
                    SocialLoginId  = command.SocialLoginId,
                    IsEnabled      = true
                };
                user.IPDetailId = user.IPDetailId == 0 ? null : user.IPDetailId;
                if (command.ReferralId != null)
                {
                    var referral = _referralRepository.GetBySlug(command.ReferralId);
                    if (referral != null)
                    {
                        user.ReferralId = referral.Id;
                    }
                }
                var userDetails = _userRepository.Save(user);

                try
                {
                    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 VisitorInfoEvent(user));
                }
            }
        }