Ejemplo n.º 1
0
        private void ValidateSyncProfileRequest(SyncProfileRequest request)
        {
            if (request.CountryIsoCode == null)
            {
                throw new InvalidOperationException("CountryIsoCode is null");
            }
            if (request.Locale == null)
            {
                throw new InvalidOperationException("Locale is null");
            }

            var countryIsoCodeMatch = request.CountryIsoCode.Length == 2;

            if (!countryIsoCodeMatch)
            {
                throw new InvalidOperationException("Country ISO code is incorrect");
            }

            var localeIsoMatch = Regex.Match(request.Locale, "^[a-z]{2}-[A-Z]{2}$|^[a-z]{2}$");

            if (!localeIsoMatch.Success)
            {
                throw new InvalidOperationException("Locale is incorrect");
            }
        }
Ejemplo n.º 2
0
 public UserInfo(SyncProfileRequest request)
 {
     UserId           = request.UserId;
     AdvertisingOptIn = request.AdvertisingOptIn;
     CountryIsoCode   = request.CountryIsoCode;
     DateModified     = request.DateModified;
     Locale           = request.Locale;
 }
Ejemplo n.º 3
0
 public SyncProfileRequest(SyncProfileRequest syncProfileRequest)
 {
     AdvertisingOptIn = syncProfileRequest.AdvertisingOptIn;
     CountryIsoCode   = syncProfileRequest.CountryIsoCode;
     DateModified     = syncProfileRequest.DateModified;
     Locale           = syncProfileRequest.Locale;
     RequestId        = syncProfileRequest.RequestId;
     UserId           = syncProfileRequest.UserId;
 }
Ejemplo n.º 4
0
 public void Post(SyncProfileRequest newRequest)
 {
     try
     {
         _userInfoProvider.AddUserInfo(newRequest);
     }
     catch (Exception exception)
     {
         Log.Error(exception, "Request processing raised an exception");
         throw exception;
     }
 }
Ejemplo n.º 5
0
 public void AddUserInfo(SyncProfileRequest newRequest)
 {
     try
     {
         ValidateSyncProfileRequest(newRequest);
         var alreadyExistingRequest = _context.MyAccountRequestBases.Find(newRequest.UserId);
         if (alreadyExistingRequest != null)
         {
             _context.MyAccountRequestBases.Remove(alreadyExistingRequest);
         }
         _context.MyAccountRequestBases.Add(newRequest);
         _context.SaveChanges();
     }
     catch (Exception exception)
     {
         Log.Error(exception, "Request processing raised an exception");
         throw exception;
     }
 }
Ejemplo n.º 6
0
 public UserInfo GetUserInfo(Guid guid)
 {
     try
     {
         using (var database = new MyAccountRequestBaseContext())
         {
             SyncProfileRequest ProfileRequest = (SyncProfileRequest)database.MyAccountRequestBases.Find(guid);
             if (ProfileRequest == null)
             {
                 throw new Exception("User not found");
             }
             return(new UserInfo(ProfileRequest));
         }
     }
     catch (Exception exception)
     {
         Log.Error(exception, "Getting user's info failed");
         throw exception;
     }
 }