public async Task <ContactInfo> AddContactInfoAsync(string message, string email) { try { ValidationGuard .StringIsValidRange(message, 5, $"Invalid {nameof(message)}"); ValidationGuard .StringIsValidRange(email, 4, $"Invalid {nameof(email)}"); var newContact = new ContactInfo() { Email = email, Message = message }; UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl) { Path = ApiConstants.CatalogEndpoint }; var requestResult = await _request.PostAsync <ContactInfo>(builder.ToString(), newContact); return(requestResult); } catch (Exception ex) { throw new ContactDataException(ex.Message); } }
public async Task <AuthenticationResponse> Authenticate(string userName, string password) { try { ValidationGuard .StringIsValidRange(userName, 4, $"Invalid {nameof(userName)}"); ValidationGuard .StringIsValidRange(password, 4, $"Invalid {nameof(password)}"); var user = new AuthenticationRequest() { UserName = userName, Password = password }; UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl) { Path = ApiConstants.AuthenticateEndpoint }; var requestResult = await this._request .PostAsync <AuthenticationRequest, AuthenticationResponse>(builder.ToString(), user); return(requestResult); } catch (Exception ex) { throw new AuthenticationDataException(ex.Message); } }
public async Task <UserShoppingCartItem> AddShoppingCartItem(ShoppingCartItem shoppingCartItem, string userId) { try { ValidationGuard .StringIsValidRange(userId, 1, $"Invalid {nameof(userId)}"); ValidationGuard .ObjectIsNull(shoppingCartItem, $"Invalid {nameof(shoppingCartItem)}"); UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl) { Path = ApiConstants.AddShoppingCartItemEndpoint }; var userShoppingCartItem = new UserShoppingCartItem { ShoppingCartItem = shoppingCartItem, UserId = userId }; var shoppingCartApiCall = await _request.PostAsync <UserShoppingCartItem>(builder.ToString(), userShoppingCartItem); return(shoppingCartApiCall); } catch (Exception ex) { throw new ShoppingCartDataServiceException(ex.Message); } }
public RedisCacheProvider(IDataConverter dataConverter, string configuration) { ValidationGuard.CheckNull(dataConverter, nameof(dataConverter)); ValidationGuard.CheckNullOrEmpty(configuration, nameof(configuration)); _dataConverter = dataConverter; _connection = ConnectionMultiplexer.Connect(configuration); }
public UserComparer(IObjectComparer primitiveComparer, IEnumerationComparer enumerationComparer) { ValidationGuard.CheckNull(primitiveComparer, nameof(primitiveComparer)); ValidationGuard.CheckNull(enumerationComparer, nameof(enumerationComparer)); _primitiveComparer = primitiveComparer; _enumerationComparer = enumerationComparer; }
public async Task <Order> AddOrderAsync(Order order) { try { ValidationGuard.ObjectIsNull(order, $"Invalid {nameof(order)}"); ValidationGuard.ObjectIsNull(order.Address, $"Invalid {nameof(order.Address)}"); ValidationGuard.ObjectIsNull(order.Pies, $"Invalid {nameof(order.Pies)}"); ValidationGuard .ValueGreatherThenEqual(order.Pies.Count, 0, $"Invalid {order.Pies}"); ValidationGuard .StringIsValidRange(order.OrderId, 1, $"Invalid {order.OrderId}"); ValidationGuard .StringIsValidRange(order.UserId, 1, $"Invalid {order.OrderId}"); ValidationGuard .ValueGreatherThenEqual(order.OrderTotal, 0, $"Invalid {order.OrderTotal}"); ValidationGuard .StringIsValidRange(order.Address.City, 2, $"Invalid {order.Address.City}"); ValidationGuard .StringIsValidRange(order.Address.Number, 4, $"Invalid {order.Address.Number}"); ValidationGuard .StringIsValidRange(order.Address.Street, 4, $"Invalid {order.Address.Street}"); ValidationGuard .StringIsValidRange(order.Address.ZipCode, 4, $"Invalid {order.Address.ZipCode}"); UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl) { Path = ApiConstants.PlaceOrderEndpoint }; var apiResult = await _request.PostAsync <Order>(builder.ToString(), order); return(apiResult); } catch (Exception ex) { throw new OrderDataServiceException(ex.Message); } }
public async Task <ShoppingCart> GetShoppingCart(string userId) { try { ValidationGuard .StringIsValidRange(userId, 1, $"Invalid {nameof(userId)}"); UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl) { Path = $"{ApiConstants.ShoppingCartEndpoint}/{userId}" }; var shoppingCartApiCall = await _request.GetAsync <ShoppingCart>(builder.ToString()); return(shoppingCartApiCall); } catch (Exception ex) { throw new ShoppingCartDataServiceException(ex.Message); } }
public EnumerationComparer(IObjectComparer primitiveComparer) { ValidationGuard.CheckNull(primitiveComparer, nameof(primitiveComparer)); _primitiveComparer = primitiveComparer; }