public ActionResult <double> Credit([Required, FromRoute] string accountNumber, [BindRequired, FromQuery] double sum, [Required, FromQuery] string memo) { double balance; try { memo = Util.Dequotify(memo); UserInputValidation.ValidateAccountNumber(accountNumber); UserInputValidation.ValidateAmount(sum); UserInputValidation.ValidateMemo(memo); var userInfo = User.GetUserInfo(); var username = userInfo.AccountsUsername; sum = Util.TruncateMoneyValue(sum); using (var session = Logic.Login(Repository, username)) { Logic.ExecuteTransaction(session, accountNumber, AccountsLib.ETransactionType.Credit, sum, memo); balance = Logic.GetBalance(session, accountNumber); } } catch (AccountsLibException ex) { return(new ActionFailureResult(new ApiResponse(500, ex.Message))); } return(balance); }
public static void Main(string[] args) { string format = @"Format: C:\Testing D:\Testing -d (delete)"; System.Console.WriteLine($"Commands: 'Exit' or 'Help'.. \n{format}"); string input = null; while (input != "Exit") { input = System.Console.ReadLine(); if (input != null) { if (input.ToLower() == "help") { System.Console.WriteLine(format); } else if (UserInputValidation.ValidInputFormat(input)) { var request = RequestBuilder.GetSyncRequest(input); var response = Bus.Request <SyncRequest, SyncResponse>(request); System.Console.WriteLine($"Files synced from {request.MainDirectory}, to: " + $"{request.SyncDirectory}, in {response.SyncTime} ms."); } } } }
public ActionResult <string> CreateClient([Required, FromBody] AltSourceNewClientDto input) { AccountsLib.Client newClient; try { UserInputValidation.ValidateUsername(input.Username); UserInputValidation.ValidateName(input.FirstName); UserInputValidation.ValidateName(input.LastName); var userInfo = User.GetUserInfo(); var username = userInfo.AccountsUsername; using (var session = Logic.Login(Repository, username)) { newClient = Logic.CreateClient(session, input.Username, input.FirstName, input.LastName); } } catch (AccountsLibException ex) { return(new ActionFailureResult(new ApiResponse(500, ex.Message))); } return(newClient?.ClientId); }
public IActionResult Put([BindRequired, FromBody] AltSourceNewUserDto input) { try { UserInputValidation.ValidateUsername(input.Username); UserInputValidation.ValidatePassword(input.Password); UserInputValidation.ValidateName(input.FirstName); UserInputValidation.ValidateName(input.LastName); UserInputValidation.ValidateAddress(input.Address); var encodedAddress = HtmlEncoder.Default.Encode(input.Address); // ReSharper disable once UnusedVariable var result = Users.CreateAltSourceUser(_userManager, input.Username, input.Password, input.FirstName, input.LastName, encodedAddress, false) .Result; if (!result.Succeeded) { return(BadRequest(result.CompileErrorMessage())); } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
static void Main(string[] args) { int option = 0; do { ChooseOption(ref option); switch (option) { case 1: float circleRadius = 0; UserInputValidation.ValidateUserInputRadius(ref circleRadius, "Enter the radius of the circle"); Area(circleRadius); break; case 2: float widthOfTheRectangle = 0; UserInputValidation.ValidateUserInput(ref widthOfTheRectangle, "Enter the width of the rectangle"); float heightOfTheRectangle = 0; UserInputValidation.ValidateUserInput(ref heightOfTheRectangle, "Enter the height of the rectangle"); AreaRectangle(widthOfTheRectangle, heightOfTheRectangle); break; case 3: float cylinderRadius = 0; UserInputValidation.ValidateUserInputRadius(ref cylinderRadius, "Enter the radius of the cylinder"); float cylinderHeight = 0; UserInputValidation.ValidateUserInput(ref cylinderHeight, "Enter the height of the cylinder"); Area(cylinderRadius, cylinderHeight); break; } } while (option != 4); }
public ActionResult <AccountHistory> GetHistory([Required, FromRoute] string accountNumber) { AccountHistory history; try { UserInputValidation.ValidateAccountNumber(accountNumber); var userInfo = User.GetUserInfo(); var username = userInfo.AccountsUsername; using (var session = Logic.Login(Repository, username)) { history = new AccountHistory { StartingBalance = 0.0, FinalBalance = 0.0, History = Logic.GetTransactionHistory(session, accountNumber) .Select(t => new Transaction(t)) .ToList() }; history.FinalBalance += history.History.Sum(t => (t.Action == ETransactionType.Credit) ? t.Amount : (-t.Amount)); } } catch (AccountsLibException ex) { return(new ActionFailureResult(new ApiResponse(500, ex.Message))); } return(history); }
///<summary> //Reading the 3 angles of a triangle, deciding whether the triangle is valid, and printing equilateral, isosceles or scalene based ///</summary> public static void CalculateTriangle() { float baseAngle1 = 0, baseAngle2 = 0, vertexAngle = 0, sum; UserInputValidation.ValidateUserInputRadius(ref baseAngle1, "Enter the first base angle:"); UserInputValidation.ValidateUserInputRadius(ref baseAngle2, "Enter the second base angle:"); UserInputValidation.ValidateUserInputRadius(ref vertexAngle, "Enter the vertex angle:"); // Calculate the sum of all angles of triangle sum = baseAngle1 + baseAngle2 + vertexAngle; // Check whether sum=180 then its a valid triangle otherwise not if (sum == 180) { Console.WriteLine("The triangle is valid."); //Check whether the triangle is equilateral if (baseAngle1 == 60 && baseAngle2 == 60 && vertexAngle == 60) { Console.WriteLine("The triangle is equilateral."); } else if (baseAngle1 == baseAngle2 || baseAngle2 == vertexAngle || baseAngle1 == vertexAngle) { Console.WriteLine("The triangle is an isosceles."); } else { Console.WriteLine("The triangle is scalene based."); } } else { Console.WriteLine("The triangle is not valid."); } }
/// <summary> /// Creates a new user in the Accounts database. The new user must be linked to a corresponding /// Identity on the Identity Server by setting the <see cref="ApplicationClaimTypes.ACCOUNTS_USERNAME"/> /// claim for that Identity /// to <c>username</c> /// </summary> /// <param name="username"> /// The username to be assigned to the new User. Must match the value of the /// <see cref="ApplicationClaimTypes.ACCOUNTS_USERNAME"/> claim type on the corresponding Identity /// on the Identity Server. /// </param> /// <returns>void</returns> public async Task <bool> CreateUser(string username) { UserInputValidation.ValidateUsername(username); var response = await this.InvokeApiAsync(Post, $"api/admin/create/user/{username}"); return(response.IsSuccessStatusCode); }
///<summary> //Calculating the surface of a circle based on the given radius ///</summary> public static void CalculateSurface() { double circleRadius = 0; UserInputValidation.ValidateUserInput(ref circleRadius, "Enter the radius of the circle"); double surface = Math.PI * Math.Pow(circleRadius, 2); Console.WriteLine("The surface of the circle is, {0:F2}", surface); }
public void Sync() { if (UserInputValidation.ValidInputFormat(MainPath, SyncPath, WithDelete)) { var request = RequestBuilder.GetSyncRequest(MainPath + " " + SyncPath + (WithDelete ? " -d" : "")); var response = bus.Request <SyncRequest, SyncResponse>(request); LastSync = $"{DateTime.Now} which took: {response.SyncTime}ms"; } }
/// <summary> /// Creates a new account bound to the client specified by <c>clientId</c>. /// </summary> /// <param name="clientId">The clientId of the owner of the account be modified.</param> /// <returns>The starting balance for the new account.</returns> /// public async Task <string> CreateAccount(string clientId) { UserInputValidation.ValidateClientId(clientId); var response = await this.InvokeApiAsync(Post, $"api/admin/create/{clientId}"); var accountId = await response.TryGetResponseContent(); return(accountId); }
internal static string GetCustomerName() { var customerName = UserInputGathering.GetStringInput("Enter Customer Name"); if (!UserInputValidation.IsValidString(customerName)) { throw new InvalidOperationException(" "); } return(customerName); }
///<summary> ///Function that read in and validates the option of the user ///</summary> public static void ChooseOption(ref int option) { do { Console.WriteLine("1. Calculate the area of a circle"); Console.WriteLine("2. Calculate the area of a rectangle"); Console.WriteLine("3. Calculate the area of a cylinder"); Console.WriteLine("4. Exit"); UserInputValidation.ValidateUserInput(ref option, "Choose an option"); } while (!(option == 1 || option == 2 || option == 3 || option == 4)); }
internal static string GetCustomerEmail() { var customerEmailAddress = UserInputGathering.GetStringInput("Enter Customer Email"); if (!UserInputValidation.IsValidEmailAddress(customerEmailAddress)) { throw new InvalidOperationException(" "); } return(customerEmailAddress); }
internal static int GetEmployeeId() { var employeeId = UserInputGathering.GetIntergerInput("Please enter the Employee ID"); if (UserInputValidation.IsValidIntegerValue(employeeId) == false) { throw new InvalidOperationException(" "); } return(employeeId); }
internal static string GetBillPaymemtMode() { var billPaymentMode = UserInputGathering.GetStringInput("Enter Bill Payment Mode"); if (!UserInputValidation.IsValidString(billPaymentMode)) { throw new InvalidOperationException(" "); } return(billPaymentMode); }
internal static string GetCustomerIdentity() { var customerIdentity = UserInputGathering.GetStringInput("Enter Customer Identity Type"); if (!UserInputValidation.IsValidCustomerIdentity(customerIdentity)) { throw new InvalidOperationException(" "); } return(customerIdentity); }
internal static int GetMobileNumber() { var mobileNumber = UserInputGathering.GetIntergerInput("Please enter the Customer Mobile Number"); if (UserInputValidation.IsValidMobileNumber(mobileNumber) == false) { throw new InvalidOperationException("Mobile Number not valid "); } return(mobileNumber); }
/// <summary> /// This method accepts a character input and validates if it is a letter. /// </summary> /// <param name="descriptionString">Description String for display</param> /// <returns>character Input</returns> private static char GetCharacterInput(string descriptionString) { var character = UserInputGathering.GetCharacterInput(descriptionString); if (!UserInputValidation.IsValidLetter(character)) { throw new InvalidOperationException(" "); } return(character); }
/// <summary> /// This method accepts and validates the String Input /// </summary> /// <returns>Returns the String inputted by User</returns> internal static string GetUserInputString() { var userInputString = UserInputGathering.GetStringInput(); if (!UserInputValidation.IsValidString(userInputString)) { throw new InvalidOperationException(" "); } return(userInputString); }
/// <summary> /// This method prompts user for height of triangle /// </summary> internal static int SetHeightOfTriangle() { var heightOfTriangle = UserInputGathering.GetIntergerInput("Please enter the height of star triangle"); if (UserInputValidation.IsValidHeightofTriangle(heightOfTriangle) == false) { throw new InvalidOperationException(" "); } return(heightOfTriangle); }
/// <summary> /// Get the history of an account from the Accounts API. /// </summary> /// <param name="accountNumber">The account to be queried.</param> /// <returns>The account history as list of signed doubles.</returns> /// public async Task <AccountHistory> GetAccountHistory(string accountNumber) { UserInputValidation.ValidateAccountNumber(accountNumber); var response = await this.InvokeApiAsync(Get, $"api/accounts/history/{accountNumber}"); var content = await response.TryGetResponseContent(); var history = JsonConvert.DeserializeObject <AccountHistory>(content); return(history); }
/// <summary> /// This method forms the character aray to print triangle by prompting user for Start and End Characters /// </summary> /// <returns>returns a character array from start character to end character</returns> internal static char[] SetCharacterArrayUsingStartEndCharacters() { var startCharacter = GetCharacterInput("\nPlease enter an input start character : "); var endCharacter = GetCharacterInput("\nPlease enter an input end character : "); UserInputValidation.ValidateStartAndEndCharacter(startCharacter, endCharacter); var characterArray = ExtendedUserUtilities.GenerateCharacterArray(startCharacter, endCharacter); return(characterArray); }
/// <summary> /// Get the balance of an account from the Accounts API. /// </summary> /// <param name="accountNumber">The account to be queried.</param> /// <returns>The account balance as a double.</returns> /// public async Task <double> GetAccountBalance(string accountNumber) { UserInputValidation.ValidateAccountNumber(accountNumber); var response = await this.InvokeApiAsync(Get, $"api/accounts/balance/{accountNumber}"); var content = await response.TryGetResponseContent(); var balance = Double.Parse(content); return(balance); }
private int GetNumberInput() { Console.WriteLine("Enter any number"); var inputNumber = Console.ReadLine(); if (UserInputValidation.NumberNegativeOrInvalid(inputNumber)) { Console.WriteLine("Please enter a positive number, try again:"); GetNumberInput(); } return(int.Parse(inputNumber)); }
public string Play() { Console.WriteLine("Pick a number, any number and I will sum all the numbers from 1 to N!"); var inputNumber = Console.ReadLine(); if (UserInputValidation.NumberNegativeOrInvalid(inputNumber)) { Console.WriteLine("Please enter a positive number, try again:"); Play(); } return(OperationFromOneToN.Sum(int.Parse(inputNumber))); }
public int GetUserGameSelection() { var gameSelection = Console.ReadLine(); var validInput = UserInputValidation.GameSelectionCheck(gameSelection); if (!validInput) { Console.WriteLine("Please enter a valid number, try again:"); return(GetUserGameSelection()); } return(int.Parse(gameSelection)); }
public string Play() { Console.WriteLine("Enter a number and I will return the sum of all multiples of 3 or 5 from 1 to N"); var inputNumber = Console.ReadLine(); if (UserInputValidation.NumberNegativeOrInvalid(inputNumber)) { Console.WriteLine("Please enter a positive number, try again:"); Play(); } return(SumNumbersIfMultiplesOf3Or5(int.Parse(inputNumber))); }
public async Task <string> CreateClient(string username, string firstName, string lastName) { UserInputValidation.ValidateUsername(username); UserInputValidation.ValidateName(firstName); UserInputValidation.ValidateName(lastName); var newClient = new AltSourceNewClientDto(username, firstName, lastName); var jsonNewUser = JsonConvert.SerializeObject(newClient); var content = new StringContent(jsonNewUser, Encoding.UTF8, "application/json"); var response = await this.InvokeApiAsync(Post, @"api/admin/create/client", content); var newClientId = await response.TryGetResponseContent(); return(newClientId); }
public ActionResult <bool> CreateUser([Required, FromRoute] string newUsername) { UserInputValidation.ValidateUsername(newUsername); var userInfo = User.GetUserInfo(); var username = userInfo.AccountsUsername; using (var session = Logic.Login(Repository, username)) { // ReSharper disable once UnusedVariable var newUser = Logic.CreateUser(session, newUsername); } return(true); }