public Response <Sub> Sub([FromBody] SubDto sub) { return(Extension.Try <Sub>(() => { string TrackingId = null; var re = Request; var headers = re.Headers; Sub Difference = this.serviceCalculators.Sub(sub.Minuend, sub.Subtrahend); //If a 'TrackingId’ was provided, the server should store this request’s details inside it’s //journal, indexed by the given Id. TrackingId = ValidateTrackingId(); if (!string.IsNullOrEmpty(TrackingId)) { Operations operation = new Operations() { Id = TrackingId, Operation = "Sub", Date = DateTime.UtcNow.ToString("s") + "Z", Calculation = sub.Minuend + "-" + sub.Subtrahend + "=" + Difference.Difference }; this.serviceCalculators.SaveJournal(operation); } return Difference; }, _logger)); }
public async Task <SubResponseDto> Subtraction(SubDto sub, string trackingId) { var result = (Math.Abs(sub.Minuend) - Math.Abs(sub.Subtrahend)); var response = new SubResponseDto { Difference = result }; await _journal.AddJournalOperation(EnumOperationsType.Sub, sub, response, trackingId); return(response); }
static void Main(string[] args) { string trackingId = "1143326479"; List <int> Addends = new List <int>(); Addends.Add(3); Addends.Add(3); Addends.Add(2); SubDto subdto = new SubDto() { Minuend = 5, Subtrahend = 3 }; List <int> Factors = new List <int>(); Factors.Add(8); Factors.Add(3); Factors.Add(2); MultDto multdto = new MultDto() { Factors = Factors }; DivDto divdto = new DivDto() { Dividend = 4, Divisor = 2 }; SqrtDto sqrtdto = new SqrtDto() { Number = 6 }; QueryDto queryDto = new QueryDto() { Id = trackingId }; Add(Addends, trackingId).Wait(); Sub(subdto, trackingId).Wait(); Mult(multdto, trackingId).Wait(); Div(divdto, trackingId).Wait(); Sqrt(sqrtdto, trackingId).Wait(); Query(queryDto).Wait(); Console.Read(); }
public void TestTupleSources() { TypeAdapterConfig <(Dto, SubDto), Poco> .NewConfig() .Map(dest => dest, src => src.Item1) .Map(dest => dest, src => src.Item2); var dto = new Dto { Name = "foo" }; var sub = new SubDto { Extras = "bar" }; var poco = (dto, sub).Adapt <Poco>(); poco.Name.ShouldBe(dto.Name); poco.Extras.ShouldBe(sub.Extras); }
static async Task Sub(SubDto sub, string trackingId) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); if (!string.IsNullOrEmpty(trackingId)) { client.DefaultRequestHeaders.Add("X-Evi-Tracking-Id", trackingId); } HttpResponseMessage responsePost = await client.PostAsJsonAsync("api/calculator/sub", sub); if (responsePost.IsSuccessStatusCode) { // Get the URI of the created resource. // Console.WriteLine(responsePost.Content.ReadAsStringAsync().Result); Response <Sub> difference = JsonConvert.DeserializeObject <Response <Sub> >(responsePost.Content.ReadAsStringAsync().Result); Console.WriteLine(string.Format("Difference: {0}", difference.Data.Difference)); } } }
public async Task <SubResponseDto> Sub([FromHeader(Name = "X-Evi-TrackingId")] string trackingId, [FromBody] SubDto sub) { _loggerManager.LogInfo("Call 'Sub' post method on CalculatorController"); if (sub == null) { _loggerManager.LogError("BadRequestException on calls 'Sub' post method on CalculatorController"); throw new BadRequestException("Unable to process request: Sub"); } try { var result = await _calculator.Subtraction(sub, trackingId); return(result); } catch (System.Exception ex) { _loggerManager.LogError("InternalErrorException on calls 'Sub' post method on CalculatorController", ex); throw new InternalErrorException("An unexpected error condition was triggered which made impossible to fulfill the request. Please try again later."); } }