public Response <Sqrt> Sqrt([FromBody] SqrtDto sqrtdto) { return(Extension.Try <Sqrt>(() => { string TrackingId = null; Sqrt Restul = this.serviceCalculators.Sqrt(sqrtdto.Number); //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 = "Sqrt", Date = DateTime.UtcNow.ToString("s") + "Z", Calculation = sqrtdto.Number + " square " + "=" + Restul.Square }; this.serviceCalculators.SaveJournal(operation); } return Restul; }, _logger)); }
public async Task <SqrtResponseDto> SquareRoot(SqrtDto sqr, string trackingId) { var result = Math.Sqrt(sqr.Number); var response = new SqrtResponseDto { Square = result }; await _journal.AddJournalOperation(EnumOperationsType.Sqr, sqr, response, trackingId); return(response); }
public async Task <ActionResult <OperationDto> > Sqrt(SqrtDto sqrtDto) { try { Operation operation = await operationService.Sqrt(sqrtDto.OperationId, sqrtDto.Operand); return(Ok(OperationMapper.Map(operation))); } catch (Exception ex) { logger.Error(ex, ex.Message); return(Problem("There was a problem processing your request", statusCode: (int?)HttpStatusCode.InternalServerError)); } }
internal async Task <OperationDto> SquareRoot() { Console.WriteLine("Please, specify operand."); SqrtDto dto = new SqrtDto(); dto.Operand = double.Parse(Console.ReadLine()); Console.WriteLine("If you want to store the calculation, please, specify a new id."); int?id = null; if (int.TryParse(Console.ReadLine(), out int tmp)) { id = tmp; } return(await DoOperation(dto, id, SquareRootRoute)); }
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(); }
static async Task Sqrt(SqrtDto sqrtdto, 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/sqrt", sqrtdto); if (responsePost.IsSuccessStatusCode) { // Get the URI of the created resource. // Console.WriteLine(responsePost.Content.ReadAsStringAsync().Result); Response <Sqrt> sqrt = JsonConvert.DeserializeObject <Response <Sqrt> >(responsePost.Content.ReadAsStringAsync().Result); Console.WriteLine(string.Format("Square: {0}", sqrt.Data.Square)); } } }
public async Task <SqrtResponseDto> Sqrt([FromHeader(Name = "X-Evi-TrackingId")] string trackingId, [FromBody] SqrtDto sqr) { _loggerManager.LogInfo("Call 'Sqrt' post method on CalculatorController"); if (sqr == null) { _loggerManager.LogError("BadRequestException on calls 'Sqrt' post method on CalculatorController"); throw new BadRequestException("Unable to process request: Sqrt"); } try { var result = await _calculator.SquareRoot(sqr, trackingId); return(result); } catch (System.Exception ex) { _loggerManager.LogError("InternalErrorException on calls 'Sqrt' 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."); } }