public ApiResponseOperations Calculate(string contractType, string salary) { string api = $"{urlApi}/GetSalary/{contractType}/{salary}"; var request = (HttpWebRequest)WebRequest.Create(api); request.Method = "GET"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"; request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; var response = (HttpWebResponse)request.GetResponse(); string content = string.Empty; using (var stream = response.GetResponseStream()) { using (var sr = new StreamReader(stream)) { content = sr.ReadToEnd(); } } string result = string.Empty; JavaScriptSerializer js = new JavaScriptSerializer(); ApiResponseOperations con = js.Deserialize <ApiResponseOperations>(content); return(con); }
public ApiResponseOperations GetSalary(string contractTypeName, string salary) { ApiResponseOperations response = new ApiResponseOperations(); try { decimal result = 0; decimal sa = Convert.ToDecimal(salary); const string contractHour = "HourlySalaryEmployee"; const string contractMonth = "MonthlySalaryEmployee"; switch (contractTypeName) { case contractHour: var calH = new CalculateHourlySalary(); result = calH.Calculate(sa); break; case contractMonth: var calM = new CalculateMonthlySalary(); result = calM.Calculate(sa); break; } response.Data = result; response.Message = "OK"; response.Success = true; } catch (Exception ex) { response.Message = $"Error: {ex.Message}"; response.Success = false; } return(response); }