Beispiel #1
0
        public ActionResult Calculator()
        {
            try
            {
                ViewBag.Message = "Калькулятор";
                if (ViewBag.Message == null)
                {
                    STLogger.Warn("ViewBag.Message = null");
                }
                else
                {
                    STLogger.Info("set ViewBag.Message = " + ViewBag.Message);
                }

                coordinates = new List <Coordinate>();
                JsonFile.Write(coordinates);
                //coordinates = (List<Coordinate>)this.Session["list"] ?? new List<Coordinate>();
                //coordinates = new List<Coordinate>() { new Coordinate { X = 2, Y = 2 }, new Coordinate { X = 3, Y = 5 },
                //    new Coordinate { X = 6, Y = 3 }, new Coordinate { X = 2, Y = 2 } };
                double x = 0, y = 0;
                //if (coordinates == null)
                //    STLogger.Warn("coordinates = null");
                //else if(coordinates.Count <= 3)
                //    STLogger.Warn("coordinates Count = " + coordinates.Count.ToString());
                //else
                //{
                //    STLogger.Debug("Start sum to X");
                //    x = Sum.SumX(coordinates);
                //    STLogger.Debug("Start sum to Y");
                //    y = Sum.SumY(coordinates);
                //    STLogger.Debug("Complete sum ");
                //}

                ViewData["graf"] = coordinates;
                STLogger.Info("set ViewData[\"graf\"]");
                ViewBag.Result = coordinates?.StringFormat();
                ViewBag.X      = string.Format("sumX = {0}", x.ToString("N2"));
                ViewBag.Y      = string.Format("sumY =  {0}", y.ToString("N2"));
                ViewBag.Square = string.Format("Square is {0}", (x == y).ToString());
            }
            catch (Exception ex)
            {
                STLogger.Error(ex.Message);
            }
            finally
            {
                STLogger.Start();
            }

            return(View());
        }
Beispiel #2
0
        public ActionResult Calculator(Coordinate coordinate)
        {
            if (ModelState == null)
            {
                STLogger.Warn("ModelState = null");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    ViewBag.Message = "Калькулятор";
                    if (ViewBag.Message == null)
                    {
                        STLogger.Warn("ViewBag.Message = null");
                    }
                    else
                    {
                        STLogger.Info("set ViewBag.Message = " + ViewBag.Message);
                    }
                    STLogger.Info("ModelState.IsValid " + ModelState.IsValid.ToString());

                    coordinates = JsonFile.Read();
                    //coordinates = (List<Coordinate>)this.Session["list"] ?? new List<Coordinate>();
                    if (coordinates == null)
                    {
                        STLogger.Warn("coordinates = null");
                    }

                    STLogger.Info("init coordinates.");

                    coordinates.Add(coordinate);
                    STLogger.Info("Add new coordinate to coordinates.");

                    JsonFile.Write(coordinates);
                    STLogger.Info("Write coordinates to session");
                    double x = 0, y = 0;
                    if (coordinates == null)
                    {
                        STLogger.Warn("coordinates = null");
                    }
                    else if (coordinates.Count <= 3)
                    {
                        STLogger.Warn("coordinates Count = " + coordinates.Count.ToString());
                    }
                    else
                    {
                        STLogger.Debug("Start sum to X");
                        x = Sum.SumX(coordinates);
                        STLogger.Debug("Start sum to Y");
                        y = Sum.SumY(coordinates);
                        STLogger.Debug("Complete sum ");
                    }

                    STLogger.Info("init coordinates.");

                    ViewData["graf"] = coordinates;
                    STLogger.Info("set ViewData[\"graf\"]");
                    ViewBag.Result = coordinates?.StringFormat();
                    //" sumX = " + x.Value.ToString("N2") + " sumY = " + y.Value.ToString("N2") + " Square is " + (x.Value == y.Value).ToString();
                    ViewBag.X      = string.Format("sumX = {0}", x.ToString("N2"));
                    ViewBag.Y      = string.Format("sumY =  {0}", y.ToString("N2"));
                    ViewBag.Square = string.Format("Square is {0}", (x == y).ToString());
                    STLogger.Info("set ViewBag.Result");

                    STLogger.Info("Write coordinates to session");
                }
                catch (Exception ex)
                {
                    STLogger.Error(ex.Message);
                }
                finally
                {
                    STLogger.Start();
                }
                return(View("Calculator"));
            }
            else
            {
                STLogger.Warn("ModelState.IsValid " + ModelState.IsValid.ToString());
                STLogger.Start();
                return(View(coordinate));
            }
        }