示例#1
0
        public async Task <UserData> AddUserData(ParaboleModel model)
        {
            var userdata = db.UserData.Add(new UserData
            {
                RangeFrom = model.RangeFrom,
                RangeTo   = model.RangeTo,
                step      = model.step,
                a         = model.a,
                b         = model.b,
                c         = model.c
            });

            await db.SaveChangesAsync();

            return(userdata);
        }
示例#2
0
        public async Task <Dictionary <double, double> > Points(ParaboleModel model, UserData userdata)
        {
            Dictionary <double, double> points = new Dictionary <double, double>();

            for (int i = model.RangeFrom; i <= model.RangeTo; i += model.step)
            {
                points
                .Add(i, model.a * Math.Pow(i, 2) + model.b * i + model.c);

                db.Points.Add(new Point
                {
                    ChartId = userdata.UserDataId,
                    PointX  = i,
                    PointY  = model.a * Math.Pow(i, 2) + model.b * i + model.c
                });
            }
            await db.SaveChangesAsync();

            return(points);
        }
示例#3
0
        public async Task <object> Parabola(ParaboleModel model)
        {
            if (ModelState.IsValid)
            {
                double disc = Math.Pow(model.b, 2) - (4 * model.a * model.c);

                var userdata = await ChartService.AddUserData(model);

                if (disc >= 0)
                {
                    var points = await ChartService.Points(model, userdata);

                    return(points);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Введенные данные должны быть целыми числами");

                return(ModelState);
            }

            return(null);
        }