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"); } }
public UserInfo(SyncProfileRequest request) { UserId = request.UserId; AdvertisingOptIn = request.AdvertisingOptIn; CountryIsoCode = request.CountryIsoCode; DateModified = request.DateModified; Locale = request.Locale; }
public SyncProfileRequest(SyncProfileRequest syncProfileRequest) { AdvertisingOptIn = syncProfileRequest.AdvertisingOptIn; CountryIsoCode = syncProfileRequest.CountryIsoCode; DateModified = syncProfileRequest.DateModified; Locale = syncProfileRequest.Locale; RequestId = syncProfileRequest.RequestId; UserId = syncProfileRequest.UserId; }
public void Post(SyncProfileRequest newRequest) { try { _userInfoProvider.AddUserInfo(newRequest); } catch (Exception exception) { Log.Error(exception, "Request processing raised an exception"); throw exception; } }
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; } }
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; } }