Beispiel #1
0
        /// <summary>
        /// Execute register weight action.
        /// </summary>
        /// <param name="newPlot">The plot to add.</param>
        /// <returns></returns>
        public ActionResult RegisterWeightExecute(WeightPlot newPlot)
        {
            newPlot.PlotStamp = DateTime.Now;
            newPlot.PlotId = Guid.NewGuid();

            var user = _context.Users.First(x => x.PrivateToken == newPlot.PrivateToken);
            if (user == null) return Content("Lol");

            user.WeightPlots.Add(newPlot);
            _context.SaveChanges();
            return RedirectToAction("Home", new { @privateToken = newPlot.PrivateToken });
        }
Beispiel #2
0
        public ActionResult SetupDemoUser()
        {
            var rand = new Random((int)DateTime.Now.Ticks);

            var demoUser = new User
                {
                    Password = "******",
                    Username = "******",
                    PrivateToken = TokenFactory.GenerateToken(),

                };

            // First remove user.
            if (_context.Users.Count(x => x.Username == "*****@*****.**")==1)
            {
                var user = _context.Users.Find(demoUser.Username);
                var weightPlots = new WeightPlot[user.WeightPlots.Count];
                user.WeightPlots.CopyTo(weightPlots,0);

                foreach(var plot in weightPlots)
                {
                    _context.WeightPlots.Remove(plot);
                }
                _context.Users.Remove(user);
            }
            _context.SaveChanges();

            // Add user again.
            _context.Users.Add(demoUser);
            _context.SaveChanges();

            // Get the user back again.
            demoUser = _context.Users.Find(demoUser.Username);

            // Add plots.
            var date = DateTime.Parse("2011-01-01");
            var weight = 110.0;
            double weightLossPerDay = 0.20;
            const double weightLossPerDayDecay = 0.995;
            for(var i=0;i<365;i++)
            {
                var plot = new WeightPlot
                {
                    Weight = weight + (rand.NextDouble()*2),
                    PlotId = Guid.NewGuid(),
                    PlotStamp = date
                };

                // Loose weight
                weight = weight - weightLossPerDay + rand.NextDouble()/rand.Next(5,50);
                weightLossPerDay *= weightLossPerDayDecay;

                // Append +1 days.
                date = date.AddDays(1);

                // Skip most of the days.
                if (rand.Next(0, 100) > 25) continue;

                demoUser.WeightPlots.Add(plot);
            }

            _context.SaveChanges();

            return RedirectToAction("Index");
        }
Beispiel #3
0
        /// <summary>
        /// Render 'RegisterWeight' View.
        /// </summary>
        /// <param name="privateToken">The private token.</param>
        /// <returns></returns>
        public ActionResult RegisterWeight(string privateToken)
        {
            var user = LoginUsingToken(privateToken);
            if (user == null) RedirectToAction("Index");

            var plot = new WeightPlot { PrivateToken = user.PrivateToken };
            return View(plot);
        }