public IQueryable<UserLocationViewModel> Read(String UserID, String Date) { List<UserLocationViewModel> ret = new List<UserLocationViewModel>(); DateTime temp1 = DateTime.Parse(Date).AddDays(1); DateTime temp2 = DateTime.Parse(Date).AddDays(-1).AddHours(23).AddMinutes(59); var qry = db.UserLocation.Where(x => x.UserDevice.UserID == UserID && x.DeviceDT.CompareTo(temp1) < 0 && x.DeviceDT.CompareTo(temp2) > 0).OrderBy(x => x.DeviceDT); foreach (UserLocation x in qry) { //if (x.WriteDT.ToString("yyyy/MM/dd") == Date) //{ UserLocationViewModel v = new UserLocationViewModel(); v.ID = x.ID; v.UserName = x.UserDevice.UserData.UserName; v.UserID = x.UserDevice.UserID; v.Xaxis = x.Xaxis; v.Yaxis = x.Yaxis; v.DateTime = x.DeviceDT; v.DateStr = x.DeviceDT.ToString("yyyy/MM/dd"); v.TimeStr = x.DeviceDT.ToString("HH:mm"); ret.Add(v); //} } //ret = qry.Select(x => new UserLocationViewModel { // ID = x.ID, // UserName = x.UserDevice.UserData.UserName, // Xaxis = x.Xaxis, // Yaxis = x.Yaxis, // DateTime = x.WriteDT, // //DateStr = x.WriteDT.ToString("yyyy/MM/dd HH:mm"), // //TimeStr = x.WriteDT.ToString("HH:mm") //}).ToList(); return ret.AsQueryable(); }
public IQueryable<UserLocationViewModel> ReadNow(int Min,String Area) { List<UserLocationViewModel> ret = new List<UserLocationViewModel>(); DateTime temp1 = DateTime.Now; DateTime temp2 = DateTime.Now.AddMinutes((0-Min)); var qry = db.UserLocation.Where(x => x.DeviceDT.CompareTo(temp1) < 0 && x.DeviceDT.CompareTo(temp2) > 0).OrderByDescending(x => x.DeviceDT); foreach (UserLocation x in qry) { //if (x.WriteDT.ToString("yyyy/MM/dd") == Date) //{ Boolean same = false; UserLocationViewModel v = new UserLocationViewModel(); v.ID = x.ID; v.UserName = x.UserDevice.UserData.UserName; v.UserID = x.UserDevice.UserID; v.Xaxis = x.Xaxis; v.Yaxis = x.Yaxis; v.DateTime = x.DeviceDT; v.DateStr = x.DeviceDT.ToString("yyyy/MM/dd"); v.TimeStr = x.DeviceDT.ToString("HH:mm"); if (Area != "") { if (db.AreaReResponsibleClass.Where(y => y.AreaID == Area && y.ResponsibleClass.UserID == v.UserID).Count() > 0) { for (int k = 0; k < ret.Count; k++) { if (ret[k].UserID == v.UserID) same = true; } if (!same) ret.Add(v); } } else { for (int k = 0; k < ret.Count; k++) { if (ret[k].UserID == v.UserID) same = true; } if (!same) ret.Add(v); } //} } return ret.AsQueryable(); }
public IQueryable<UserLocationViewModel> ReadUserLast(String UserID) { List<UserLocationViewModel> ret = new List<UserLocationViewModel>(); var qry = db.UserLocation.Where(x => x.UserDevice.UserID == UserID).OrderByDescending(x => x.DeviceDT); foreach (UserLocation x in qry) { UserLocationViewModel v = new UserLocationViewModel(); v.ID = x.ID; v.UserName = x.UserDevice.UserData.UserName; v.UserID = x.UserDevice.UserID; v.Xaxis = x.Xaxis; v.Yaxis = x.Yaxis; v.DateTime = x.DeviceDT; v.DateStr = x.DeviceDT.ToString("yyyy/MM/dd"); v.TimeStr = x.DeviceDT.ToString("HH:mm"); ret.Add(v); break; } return ret.AsQueryable(); }