public static string Mult(MultModel oMult, string sTrackingId) { var client = new RestClient(string.Concat(ConfigurationManager.AppSettings["ServiceURL"], "/calculator/mult")); var request = new RestRequest(Method.POST); setTracking(sTrackingId, request); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("undefined", JsonConvert.SerializeObject(oMult), ParameterType.RequestBody); IRestResponse response = client.Execute(request); return(response.Content); }
public HttpResponseMessage Mult([FromBody] MultModel oMult) { int iResult = 1; MultResultModel oResult; string sTrackingID = null; try { oResult = new MultResultModel(); if (oMult != null && oMult.Factors != null && oMult.Factors.Length > 1) { foreach (int val in oMult.Factors) { iResult *= val; } oResult.Product = iResult; // Once result has been calculated, checks if Tracking ID exists // and in that case save operation and result sTrackingID = CommonUtils.checkTrackingID(Request); if (!string.IsNullOrEmpty(sTrackingID)) { CommonUtils.saveToJournal(sTrackingID, oMult, oResult); } return(Request.CreateResponse(HttpStatusCode.OK, oResult)); } // In other case input is not valid else { HttpError err = new HttpError("An invalid request has been received. This may mean the HTTP requests and/or the HTTP body may contains some errors which should be fixed."); return(Request.CreateResponse(HttpStatusCode.BadRequest, err)); } } catch (Exception ex) { // TODO: This exception should be logged somewhere // If something happens throws Internal Error HttpError err = new HttpError("An unexpected error condition was triggered which made impossible to fulfill the request. Please try again or contact support."); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, err)); } }
public override Task <CommandResult> ExecuteAsync(CancellationToken cancel) { string sResult; try { Console.WriteLine("Calculating..."); MultModel oMult = new MultModel(Factors); sResult = Operations.Mult(oMult, TrackingID); Console.WriteLine(sResult); return(Task.FromResult(CommandResult.Success)); } catch (Exception ex) { Console.WriteLine("Something wrong happend, please check arguments are valid"); return(Task.FromResult(CommandResult.UsageError)); } }