/// <summary>
        /// Implementation of addition method.
        /// </summary>
        /// <param name="addends"></param>
        /// <param name="trackingId"></param>
        /// <returns></returns>
        public AdditionResponseModel Addition(AdditionModel addends, string trackingId)
        {
            // Sums all the numbers in the array.
            int sum = 0;

            foreach (int i in addends.Addends)
            {
                sum += i;
            }

            LogModel logModel = new LogModel()
            {
                Operation   = "Sum",
                Calculation = $"{string.Join("+", addends.Addends)} = {sum.ToString()}",
                Date        = DateTime.Now
            };

            //if there is a tracking id, save operation in journal.
            if (!string.IsNullOrEmpty(trackingId))
            {
                Journal.Add(new KeyValuePair <string, LogModel>(trackingId, logModel));
            }
            // saves data in the log
            Log.Information($"Calculator::Add:: {logModel}");

            return(new AdditionResponseModel()
            {
                Sum = sum
            });
        }
        public UmbracoPageResult Add(AdditionModel model)
        {
            model.Result = model.A + model.B;
            ViewData["AdditionModel"] = model;

            return(CurrentUmbracoPage());
        }
示例#3
0
        public ActionResult Add(AdditionModel requestmodel)
        {
            AdditionModel model = new AdditionModel();// create an object of AdditionModel

            model.Result = model.Add(requestmodel);
            return(View(model));
        }
示例#4
0
 public int Calculation_Addition(AdditionModel model)
 {
     return(Go.To <CalculationsPage>().
            AdditionValue1.Set(model.Value1).
            AdditionValue2.Set(model.Value2).
            AdditionResult.Value);
 }
        public ViewResult AddForm(AdditionModel model)
        {
            if (!model.IsPosted)
            {
                return(View("AddForm", model));
            }

            model.Sum = model.X + model.Y;
            return(View("AddResult", model));
        }
示例#6
0
        public void Returns_Sum()
        {
            var controller = new SimpleSurfaceController(umbracoContext, new UmbracoHelper(umbracoContext));

            var model = new AdditionModel
            {
                IsPosted = true,
                X        = 3,
                Y        = 5
            };
            var result = (AdditionModel)controller.AddForm(model).Model;

            Assert.AreEqual(8, result.Sum);
        }
        public void Posting_AddModel_Calculates_Result()
        {
            const int expectedSum = 3;
            var       model       = new AdditionModel
            {
                X        = 1,
                Y        = 2,
                IsPosted = true
            };

            var controller  = new SimpleSurfaceController();
            var result      = controller.AddForm(model);
            var resultModel = (AdditionModel)result.Model;

            Assert.AreEqual(expectedSum, resultModel.Sum);
        }
        public ActionResult Add([FromBody] AdditionModel addends)
        {
            try
            {
                // Verifies if the model is valid, if not, returns a bad request response.
                // the verification is based on the attributes defined in the DTO.
                if (!ModelState.IsValid)
                {
                    MicroserviceException badRequestResponse = new MicroserviceException()
                    {
                        ErrorCode    = "InternalError",
                        ErrorMessage = "Unable to process request:" + ModelState.Count,
                        ErrorStatus  = 400
                    };
                    return(BadRequest(badRequestResponse));
                }
                else
                {
                    // Finds the value of the header with the tracking id
                    StringValues trackingId;
                    Request.Headers.TryGetValue("X-Evi-Tracking-Id", out trackingId);
                    var response = _calculatorService.Addition(addends, trackingId);
                    return(Ok(response));
                }
            }
            // Catches and manages all of the server's errors and responds the client with a controlled object.
            catch (Exception err)
            {
                MicroserviceException internalServerErrorResponse = new MicroserviceException()
                {
                    ErrorCode    = "InternalError",
                    ErrorMessage = "An unexpected error condition was triggered which made impossible to fulfill the request. Please try again or contact support" + err.InnerException,
                    ErrorStatus  = 500
                };
                Log.Error($"Calculator::Exception:: {internalServerErrorResponse}");

                return(StatusCode(500, internalServerErrorResponse));
            }
        }
示例#9
0
 public ActionResult Index(AdditionModel model)
 {
     model.Sum = model.FirstNumber + model.SecondNumber;
     return(this.View(model));
 }