public static void ProcessUser(string userId, User profileToProcess = null) { var db = new ApplicationDbContext(); var repo = new GriddingRepository(); var user = db.Users.Include(u => u.Zone).First(u => u.Id == userId); if (profileToProcess != null) { user.Latitude = profileToProcess.Latitude; user.Longitude = profileToProcess.Longitude; } var zones = repo.GetZones().ToList(); GetStatus(user, zones); db.SaveChanges(); }
public static bool CheckUserZoneForISPOrdering(User user) { var repo = new GriddingRepository(); var zones = repo.GetZones().ToList(); var response = false; UserSyncResponseDto result = GetStatus(user, zones); if (result.User != null && result.User.ZoneId != null) { var zone = zones.FirstOrDefault(z => z.ZoneId == result.User.ZoneId); //if the map result == true and Zone == true or Location == true if (result.IsPossible && zone != null && zone.AllowOrder) { response = true; } } return(response); }
public static void ProcessUsersTask(string precinctCode) { var db = Db.GetInstance(); var repo = new GriddingRepository(); var zones = repo.GetZones().ToList(); var usersToProcess = GetUsersForZoneProcessing(precinctCode, db); var results = new ResponseModel { TotalRequest = usersToProcess.Count }; foreach (var u in usersToProcess) { results.ResponseList.Add(GetStatus(u, zones)); } db.SaveChanges(); var usersWithErrorsString = "<table><thead><tr> <th>FullName</th> <th>Email</th> <th>Location</th> <th>Estate</th> <th>Lat-Long</th> <th>Address</th> <th>Message</th></tr></thead><tbody>"; foreach (var r in results.ResponseList) { usersWithErrorsString += string.Format("<tr><td>{0} {1}</td> <td>{2}</td> <td>{3}</td> <td>{4}</td> <td>{5},{6}</td> <td>{7}</td> <td>{8}</td> </tr>", r.User.FirstName, r.User.LastName, r.User.Email, (r.User.Location != null ? r.User.Location.Name : ""), (r.User.Estate != null ? r.User.Estate.Name : ""), r.User.Latitude, r.User.Longitude, r.User.Address, r.ErrorMessage); } usersWithErrorsString += "</tbody>"; var email = new EmailDto { Subject = precinctCode + " sync results", Body = "Precinct synced:" + (string.IsNullOrEmpty(precinctCode) ? "All precincts" : precinctCode) + "<br/><br/>No. of users attempted: " + results.TotalRequest + "<br/><br/>No. successfully processed users: " + results.ResponseList.Count(u => !u.Error) + "<br/><br/>No. of users where map responded with IsPossible = TRUE: " + results.ResponseList.Count(u => u.IsPossible) + "<br/><br/>No. of users where map responded with IsPossible = FALSE: " + results.ResponseList.Count(u => !u.IsPossible) + "<br/><br/>Users with Errors: " + usersWithErrorsString }; EmailSender.SendEmail(email); }
public List <Zone> GetZones() { return(griddingRepo.GetZones().ToList()); }