//filter out openings. private List <Openings> FilterOpenings(DateTime targetDate, TimeSlot timeSlot, InstallZone installZone) { TechDispatchContext db = new TechDispatchContext(); IEnumerable <Appointment> Apps = db.Appointments.Where(x => x.Date == targetDate); List <Openings> SelectedOpenings = new List <Openings>(); //we want to only pick days that are relevant. int day; if (DefaultOption) { day = (int)targetDate.DayOfWeek; } else { day = -1; } SelectedOpenings = db.Openings.Where(x => x.ScheduleID == ScheduleId && x.Day == day).OrderBy(x => x.InstallZone.Name).ThenBy(x => x.TimeSlot.Name).ToList(); if (timeSlot != null) { SelectedOpenings = SelectedOpenings.Where(x => x.TimeSlotId == timeSlot.TimeSlotID).ToList(); Apps = Apps.Where(x => x.TimeSlot == timeSlot); } if (installZone != null) { SelectedOpenings = SelectedOpenings.Where(x => x.InstallZoneId == installZone.InstallZoneId).ToList(); Apps = Apps.Where(x => x.Customer.Tower.InstallZone == installZone); } return(SelectedOpenings); }
public void Cancel(bool hold) { TechDispatchContext db = new TechDispatchContext(); CustomerState = hold == true ? CustomerStatus.Hold : CustomerStatus.Cancelled; if (IPID != null) { db.IPs.First(x => x.IPId == IPID).CustomerID = null; IPID = null; } PPPoEPassword = ""; PPPoEUser = ""; TowerId = null; db.SaveChanges(); }
public AppointmentDetailJson(Appointment app, TechDispatchContext db) : base(app) { AppointmentID = app.AppointmentID; CustomerName = app.Customer.Name; CustomerAddress = app.Customer.Address; CustomerPhone = app.Customer.PhoneNumber; if (app.Customer.Tower != null) { ZoneName = app.Customer.Tower.InstallZone.Name; } AppointmentType = app.AppointmentType.ToString(); Date = app.Date; TimeSlotName = app.TimeSlot.Name; if (app.FieldTech != null) { FieldTechID = app.FieldTechID; FieldTechUserID = app.FieldTech.UserID; } else { FieldTechID = null; FieldTechUserID = null; } CurrentState = app.CurrentState.ToString(); IPID = app.Customer.IPID; if (IPID != null) { IP = app.Customer.ReadIP(); } else { IP = "None"; } TowerID = app.Customer.TowerId; if (TowerID != null) { TowerName = app.Customer.Tower.TowerName; } else { TowerName = "None"; } Comments = db.Comments.Where(x => x.AppointmentId == AppointmentID).ToArray(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if ((CustomerState == CustomerStatus.Active || CustomerState == CustomerStatus.Pending) && (IPID == null || TowerId == null || CustomerSpeed == null)) { if (TowerId == null) { yield return(new ValidationResult("Tower is required!")); } if (IPID == null) { yield return(new ValidationResult("IP is required!")); } if (CustomerSpeed == null) { yield return(new ValidationResult("Speed is required!")); } } else { // do some further checks here. Make sure that the IP exists in the tower. TechDispatchContext db = new TechDispatchContext(); if (CustomerState == CustomerStatus.Active || CustomerState == CustomerStatus.Pending) { var _tower = db.Towers.DefaultIfEmpty(null).FirstOrDefault(x => x.TowerID == TowerId); if (_tower == null) { yield return(new ValidationResult("Invalid tower selected.")); } else { var _ip = _tower.IPs.DefaultIfEmpty(null).FirstOrDefault(x => x.IPId == IPID); if (_ip == null) { yield return(new ValidationResult("IP not found in tower.")); } } } // now check to see if IP isn't taken elsewhere, if it's defined. if (IPID != null && db.Customers.DefaultIfEmpty(null).FirstOrDefault(x => x.IPID == IPID && x.CustomerID != CustomerID) != null) { yield return(new ValidationResult("IP already taken.")); } } }
//filter available openings only. private List <Openings> AvailableOpenings(DateTime targetDate, TimeSlot timeSlot, InstallZone installZone, bool install = false) { TechDispatchContext db = new TechDispatchContext(); IEnumerable <Appointment> Apps = db.Appointments.Where(x => x.Date == targetDate && x.CurrentState != Appointment.AppointmentState.Cancelled && x.CurrentState != Appointment.AppointmentState.Failed && x.CurrentState != Appointment.AppointmentState.NeedsReschedule); List <Openings> SelectedOpenings = FilterOpenings(targetDate, timeSlot, installZone); //if applicable, a list of IDs that have been modified to account for minus one installs. foreach (var x in SelectedOpenings) { x.AvailableAmount = x.Amount; } foreach (var x in Apps) { try { SelectedOpenings.DefaultIfEmpty(null).FirstOrDefault(y => y.InstallZoneId == x.Customer.Tower.InstallZoneId && y.TimeSlotId == x.TimeSlotID).AvailableAmount--; } catch (NullReferenceException e) { var y = 123123; } } if (install) { foreach (var x in SelectedOpenings) { if (x.AvailableAmount > 0 && Apps.Where(y => x.InstallZoneId == y.Customer.Tower.InstallZoneId && x.TimeSlotId == y.TimeSlotID && y.AppointmentType != Appointment.AppointmentReason.Install).Count() == 0) { x.AvailableAmount--; } } } return(SelectedOpenings); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager, string authenticationType) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here TechDispatchContext db = new TechDispatchContext(); userIdentity.AddClaim(new Claim("UserRole", db.TechDispatchRoles.FirstAsync(x => x.TechDispatchRoleId == TechDispatchRoleId).Result.Name)); //to-do: Custom authorization. For now though, we simply add the authorization codes based on role. MyClaims = db.TechDispatchRoles.FirstAsync(x => x.TechDispatchRoleId >= TechDispatchRoleId).Result.AccessClaims; MyClaims.ForEach(d => userIdentity.AddClaim(new Claim(d.ClaimName, d.ClaimValue)) ); userIdentity.AddClaim(new Claim("Name", Name == null ? Email : Name)); userIdentity.AddClaim(new Claim("Email", Email)); userIdentity.AddClaim(new Claim("AuthId", AuthId.ToString())); return(userIdentity); }