public int InsertUserHeartBeat(UserHeartBeat heartbeat)
        {
            //context.UserHeartBeats.Add(heartbeat);

            SqlParameter[] Param = new SqlParameter[7];
            Param[0] = new SqlParameter("@pHeartBeatGUID", SqlDbType.UniqueIdentifier);
            Param[0].Value = heartbeat.HeartBeatGUID;
            Param[1] = new SqlParameter("@pUserGUID", SqlDbType.UniqueIdentifier);
            Param[1].Value = heartbeat.UserGUID;
            Param[2] = new SqlParameter("@pLatitude", SqlDbType.Float);
            Param[2].Value = (object)heartbeat.Latitude ?? DBNull.Value;
            Param[3] = new SqlParameter("@pLongitude", SqlDbType.Float);
            Param[3].Value = (object)heartbeat.Longitude ?? DBNull.Value;
            Param[4] = new SqlParameter("@pHeartBeatTime", SqlDbType.DateTime);
            Param[4].Value = (object)heartbeat.HeartBeatTime ?? DBNull.Value;
            Param[5] = new SqlParameter("@pCreateDate", SqlDbType.DateTime);
            Param[5].Value = (object)heartbeat.CreateDate ?? DBNull.Value;
            Param[6] = new SqlParameter("@pCreateBy", SqlDbType.UniqueIdentifier);
            Param[6].Value = (object)heartbeat.CreateBy ?? DBNull.Value;

            return context.Database.ExecuteSqlCommand("insert into  UserHeartBeats(HeartBeatGUID,UserGUID,Latitude,Longitude,HeartBeatTime,CreateDate,CreateBy)"
              + "values(@pHeartBeatGUID,@pUserGUID,@pLatitude,@pLongitude,@pHeartBeatTime,@pCreateDate,@pCreateBy)", Param);

        }
Esempio n. 2
0
        public int PostHeartBeat(HeartBeatRequest HeartBeatRequest, Guid UserGUID)
        {
            try
            {
                int result = 0;
                IUserRepository _IUserRepository;
                _IUserRepository = new UserRepository(new WorkersInMotionDB());
                UserHeartBeat _userHeartBeat = new UserHeartBeat();
                _userHeartBeat.HeartBeatGUID = Guid.NewGuid();
                _userHeartBeat.UserGUID = UserGUID;
                _userHeartBeat.Latitude = HeartBeatRequest.latitude;
                _userHeartBeat.Longitude = HeartBeatRequest.longitude;
                _userHeartBeat.HeartBeatTime = HeartBeatRequest.time;
                _userHeartBeat.CreateDate = DateTime.UtcNow;
                _userHeartBeat.CreateBy = UserGUID;
                result = _IUserRepository.InsertUserHeartBeat(_userHeartBeat);
                //result = _IUserRepository.Save();
                return result;
            }
            catch (Exception ex)
            {
                return 0;
            }

        }