Exemplo n.º 1
0
        protected override void Seed(DailyWeightContext context)
        {
            base.Seed(context);
#if DEBUG
            if (!context.DailyWeights.Any())
            {
                decimal weight  = 230;
                var     random  = new Random();
                decimal bodyFat = (decimal)23.7;
                for (int i = 182; i > 0; i--)
                {
                    var dailyWeight = new DailyWeight
                    {
                        UserName   = "******",
                        Weight     = weight + (decimal)(random.NextDouble() * 2),
                        WeightDate = DateTime.Today.AddDays(-1 * i),
                        BodyFat    = bodyFat
                    };
                    context.DailyWeights.Add(dailyWeight);
                    weight  = weight - 0.2857M;
                    bodyFat = bodyFat - 0.02M;
                }

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                }
            }
#endif
        }
Exemplo n.º 2
0
 public bool AddDailyWeight(DailyWeight newWeight)
 {
     try
     {
         var weight =
             _ctx.DailyWeights.SingleOrDefault(
                 d => d.UserName == newWeight.UserName && d.WeightDate == newWeight.WeightDate);
         if (weight == null)
         {
             _ctx.DailyWeights.Add(newWeight);
         }
         else
         {
             newWeight.DailyWeightId = weight.DailyWeightId;
             newWeight.BodyFat       = weight.BodyFat;
             weight.Weight           = newWeight.Weight;
         }
         return(true);
     }
     catch (Exception ex)
     {
         //TODO add logging
         return(false);
     }
 }