public override void ProcessData(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, byte[] data)
        {
            int? userId = data[0];
            float weight = BitConverter.ToInt16(data, 1) / 10.0f;

            // user not specified
            if (userId == 0)
            {
                userId = FindUserBasedOnHistory(ctx, weight);
            }

            if (userId == null)
            {
                _log.Error("Could not find user based on weight '" + weight + "'");
                return;
            }

            _log.Info("Weight received for user [" + userId + "]: " + weight);

            WirelessScaleData wirelessScaleData = new WirelessScaleData
            {
                UserId = userId.Value,
                Value = weight,
                ZigBeeDevice = device,
                ReceivedDateTime = DateTime.Now
            };
            ctx.DbCtx.WirelessScaleDatas.AddObject(wirelessScaleData);
            ctx.DbCtx.SaveChanges();
        }
예제 #2
0
        public ActionResult ManualInput(DateTime date, string time, double weight)
        {
            int? userId = CoordinatorUser.Finder.GetCurrentUserId();
            if (userId == null)
            {
                throw new Exception("You must be logged in");
            }

            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                DateTime t = DateTime.Parse(date.ToString("d") + " " + time);

                WirelessScaleData data = new WirelessScaleData
                {
                    UserId = userId.Value,
                    ReceivedDateTime = t,
                    Value = weight,
                    ZigBeeDevice = null
                };
                ctx.DbCtx.WirelessScaleDatas.AddObject(data);
                ctx.DbCtx.SaveChanges();
            }

            return RedirectToAction("Index", new { userId = userId });
        }