public List <RouteNotif> GetNotifState(UserModel user) { var res = new List <RouteNotif>(); using (var dataModel = new Mibarim_plusEntities()) { var notifs = dataModel.PassNotifs.Where(x => x.UserId == user.TuserId); for (int i = 1; i <= 6; i++) { var noti = new RouteNotif(); var theNotif = notifs.FirstOrDefault(x => x.StationRouteId == i); noti.StationRouteId = i; var stationName = GetStationName(i); if (theNotif != null) { if (theNotif.NotifStatus == (int)NotifStatus.On) { noti.RouteText = stationName + " روشن "; } else { noti.RouteText = stationName + " خاموش"; } noti.Status = theNotif.NotifStatus; } else { noti.RouteText = stationName + " خاموش"; noti.Status = (int)NotifStatus.Off; } res.Add(noti); } } return(res); }
public RouteNotif GetNotifRoute() { using (var dataModel = new Mibarim_plusEntities()) { var current = DateTime.Now; //var nexthour = DateTime.Now.AddHours(1); var nexthalfhour = DateTime.Now.AddMinutes(30); var readytoNotif = dataModel.PassengerRoutes.Where( x => x.IsDeleted == false && x.PassTime > current && x.PassTime < nexthalfhour && x.NotifSeq == (int)NotifSeq.NotNotifed).ToList(); RouteNotif res = null; if (readytoNotif.Count > 0) { foreach (var passengerRoute in readytoNotif) { if (res == null) { res = new RouteNotif(); res.StationRouteId = passengerRoute.StationRouteId; } if (res != null && res.StationRouteId == passengerRoute.StationRouteId) { passengerRoute.NotifSeq = (int)NotifSeq.OneNotifed; dataModel.SaveChanges(); } } return(res); } /*var readyto2Notif = * dataModel.PassengerRoutes.FirstOrDefault( * x => * x.IsDeleted == false && x.PassTime > current && * x.PassTime < nexthalfhour && x.NotifSeq == (int)NotifSeq.OneNotifed); * if (readyto2Notif != null) * { * var res = new RouteNotif(); * res.StationRouteId = readyto2Notif.StationRouteId; * readyto2Notif.NotifSeq = (int)NotifSeq.TwoNotifed; * dataModel.SaveChanges(); * return res; * }*/ } return(null); }