public async Task <IActionResult> Add([FromBody] Number num)
        {
            _log.LogInformation("add");
            int result = 0;

            try
            {
                await _mathDbContext.AddLog(1, $"Required {JsonConvert.SerializeObject(num)}");

                result = await _calculatorSoap.AddAsync(num.NumOne, num.NumTwo);

                _log.LogInformation("result succesfull", result);

                await _mathDbContext.AddLog(1, $"Response {result} & {JsonConvert.SerializeObject(num)}");

                return(Ok(result));
            }
            catch (Exception ex)
            {
                await _mathDbContext.AddLog(1, $"Required {JsonConvert.SerializeObject(num)}");

                await _mathDbContext.AddLog(1, "Error");

                _log.LogError("Request dont correct", ex);
                throw;
            }
        }
        public async Task <ActionResult <int> > Get_AddAsync(int first, int second)
        {
            try
            {
                await _dbContext.Logs.AddAsync(new Model.Log
                {
                    Value = $" Request To Soap"
                });

                CalculatorSoapClient soapClient = new CalculatorSoapClient(CalculatorSoapClient.EndpointConfiguration.CalculatorSoap12);
                int result = await soapClient.AddAsync(first, second);

                await _dbContext.Logs.AddAsync(new Model.Log
                {
                    Value = $" Response from Soap "
                });

                await _dbContext.SaveChangesAsync();

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
        public async Task <IActionResult> Add([FromBody] Num num)
        {
            _lg.LogInformation("add");
            int result = 0;

            try
            {
                await _context.AddLog(1, $"Required {JsonConvert.SerializeObject(num)}");

                result = await _calculatorSoap.AddAsync(num.Num1, num.Num2);

                _lg.LogInformation("succes", result);

                await _context.AddLog(1, $"Response {result} & {JsonConvert.SerializeObject(num)}");

                return(Ok(result));
            }
            catch (Exception e)
            {
                await _context.AddLog(1, $"Required {JsonConvert.SerializeObject(num)}");

                await _context.AddLog(1, "Error");

                _lg.LogError("Error", e);
                throw;
            }
        }
        public async Task <ActionResult> AddAsync([FromQuery] Number number)
        {
            try
            {
                bool flag = _db.CalcFunctions.Any(r => r.Id == 1);
                if (!flag)
                {
                    _logger.LogError($"Warning Warning Warning CalcFunction Don't Exist");
                    throw new ArgumentException("Please Get Connecting with Owner");
                }

                int result = await _calculatorSoap.AddAsync(number.Number_1, number.Number_2);

                string message = Message.Info(number, (int)CalcOperation.Operation.Add, result);

                await _db.WriteDbContext(1, message);

                _logger.LogInformation(message);

                return(Content($"Adding {number.Number_1} + {number.Number_2} = {result}"));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Warning Warning Warning in Adding Method ! {ex}");
                throw new ArgumentException("Please Get Connecting with Owner");
            }
        }
Example #5
0
        public async Task <IActionResult> Add([FromBody] Number number)
        {
            _logger.LogInformation("start add method");
            int result = 0;

            if (ModelState.IsValid)
            {
                FirstTable first = null;
                try
                {
                    result = await CalculatorSoapClient.AddAsync(number.IntA, number.IntB);

                    _logger.LogInformation("result successful");
                    first = new FirstTable();
                    _db.firstTables.Add(first);
                    await _db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    _logger.LogInformation("Request dont coreect", ex);
                    throw;
                }
                _db.secondTables.Add(new SecondTable(first.Id, result.ToString()));
                await _db.SaveChangesAsync();

                _logger.LogInformation("Successful");
                return(Ok(result));
            }

            return(BadRequest());
        }
        public async void Add_2_3_Return_5()
        {
            // Act
            var result = await _controller.AddAsync(2, 3);

            // Assert
            Assert.Equal("5", result.ToString());
        }
Example #7
0
        public async Task <int> Add(int value1, int value2)
        {
            await _client.OpenAsync();

            var result = await _client.AddAsync(value1, value2);

            await _client.CloseAsync();

            return(result);
        }
        public async Task <IActionResult> AddAsync([FromBody] Number number)
        {
            int result = 0;

            if (ModelState.IsValid)
            {
                _logger.LogInformation((int)CalculateEnum.Add, "Request to Json", "Method started ");
                try
                {
                    _logger.LogInformation((int)CalculateEnum.Add, "Request to Soap", "Request sent");
                    result = await _soapClient.AddAsync(number.FirstNumber, number.SecondNumber);

                    _logger.LogInformation((int)CalculateEnum.Add, "Response from Soap", "Request success");

                    using (var transaction = await _dbContext.Database.BeginTransactionAsync())
                    {
                        Table table = new Table();
                        _dbContext.Tables.Add(table);
                        await _dbContext.SaveChangesAsync();

                        SecondTable second = new SecondTable
                        {
                            Value   = result.ToString(),
                            TableId = table.Id
                        };
                        await _dbContext.SecondTables.AddAsync(second);

                        await _dbContext.SaveChangesAsync();

                        await transaction.CommitAsync();
                    }
                }
                catch (Exception exp)
                {
                    _logger.LogError((int)CalculateEnum.Add, "Error message", exp.Message);
                    return(BadRequest(exp.Message));
                }
                return(Ok(result));
            }
            return(BadRequest(ModelState));
        }
Example #9
0
        public async Task <IActionResult> Add([FromBody] NumCalculator number)
        {
            try
            {
                var data = JsonConvert.SerializeObject(number);
                _logger.LogInformation(string.Format(Messages.Request, "Add", data));

                await _dbContext.Reports.AddAsync(new Report
                {
                    MethodId = 1,
                    VALUE    = string.Format(Messages.Request, "Add", data)
                });

                await _dbContext.SaveChangesAsync();

                var response = await _calculatorSoap.AddAsync(number.FirstNum, number.SecondNum);

                await _dbContext.Reports.AddAsync(new Report
                {
                    MethodId = 1,
                    VALUE    = string.Format(Messages.Response, "Add", response, data)
                });


                await _dbContext.SaveChangesAsync();

                _logger.LogInformation("The control is succesfully", response);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));
            }
        }
Example #10
0
 public async Task <int> AddCalcAsync(int a, int b)
 {
     return(await _client.AddAsync(a, b));
 }
Example #11
0
        static void Main(string[] args)
        {
            var client = new CalculatorSoapClient(CalculatorSoapClient.EndpointConfiguration.CalculatorSoap12);

            var result = client.AddAsync(2, 7).Result;
        }
        public async Task <ActionResult <string> > AddAsync(int value1, int value2)
        {
            int result = await _calculatorSoapClient.AddAsync(value1, value2);

            return(result.ToString());
        }