public OpenShiftDTO GetOpenShifts() { OpenShiftDTO model = new OpenShiftDTO(); var email = HttpContext.Current.User.Identity.Name; //Get the user info. var users = db.UserProfiles.FirstOrDefault(k => k.Email == email && k.IsRegisteredExternal == true); if (users != null) { // check if the user is an employee. model.IsExternalandEmp = users.Employees.Any(a => a.Email == email && a.UserProfile.Id != null); } else { model.IsEmployee = db.Employees.Any(a => a.Email == email && a.UserProfile.Id != null); } // Temporary List of data for Distance Dropdown. List <DropDownDTO> DistanceListStatic = new List <DropDownDTO>(); DistanceListStatic.Add(new DropDownDTO { Value = 1, Text = "1 Kms" }); DistanceListStatic.Add(new DropDownDTO { Value = 5, Text = "5 Kms" }); DistanceListStatic.Add(new DropDownDTO { Value = 10, Text = "10 Kms" }); DistanceListStatic.Add(new DropDownDTO { Value = 20, Text = "20 Kms" }); model.Distance = DistanceListStatic; //Filter by Choice dropdown.. List <DropDownDTO> FilterByChoice = new List <DropDownDTO>(); FilterByChoice.Add(new DropDownDTO { Value = 1, Text = "Distance" }); FilterByChoice.Add(new DropDownDTO { Value = 2, Text = "Total Pay" }); FilterByChoice.Add(new DropDownDTO { Value = 3, Text = "Hourly Rate" }); model.Filter = FilterByChoice; return(model); //return model; }
private ExternalShiftEmployeeIndexDTO ExternalShiftEpmloyee(OpenShiftDTO location, string distance) { var email = HttpContext.Current.User.Identity.Name; ExternalShiftEmployeeIndexDTO retVal = new ExternalShiftEmployeeIndexDTO(); retVal.ExternalShits = GetExternalShiftsList(location, distance); var empExternalShiftRequests = from sr in db.ExternalShiftRequests where sr.CreatedBy.Email == email && sr.Type == ExternalShiftRequestType.TakeExternalShift select sr.ExternalShiftBroadcast.Id; retVal.ExternalShiftRequests = empExternalShiftRequests.AsEnumerable(); return(retVal); }
private IEnumerable <ExternalBroadcastDTO> GetExternalShiftsList(OpenShiftDTO location, string distancekm) { var email = HttpContext.Current.User.Identity.Name; var dtNow = WebUI.Common.Common.DateTimeNowLocal(); List <ExternalBroadcastDTO> ExternalBroadCastList = new List <ExternalBroadcastDTO>(); //Getting user info from userProfile. var userinfo = db.UserProfiles.Where(a => a.Email == email && a.IsRegisteredExternal == true).FirstOrDefault(); if (userinfo != null) { //Get user Qualifications var userQualifications = db.UserQualifications.Where(a => a.UserProfileId == userinfo.Id).ToList(); List <Guid> userQuailificaions = new List <Guid>(); List <Guid> userSkill = new List <Guid>(); foreach (var item in userQualifications) { userQuailificaions.Add(item.QualificationslookupQualificationId); } //Get user Skill var userSkills = db.UserSkills.Where(a => a.UserProfileId == userinfo.Id).ToList(); foreach (var skill in userSkills) { userSkill.Add(skill.IndustrySkillsId); } //Need to make status same as ShiftChangeRequestStatus var externalShifts = db.ExternalShiftBroadcasts.Where(a => a.Status == ExternalShiftStatus.Pending).ToList(); foreach (var externalShift in externalShifts) { //Get ExternalShiftBroadCast List <Guid> externalShiftQuilificaion = new List <Guid>(); List <Guid> externalShiftSkills = new List <Guid>(); //Get ExternalShiftQualifications foreach (var item in externalShift.ShiftQualifications) { var ExternalShiftQualification = db.ExternalShiftQualifications.Where(a => a.Id == item.Id).FirstOrDefault(); externalShiftQuilificaion.Add(ExternalShiftQualification.QualificationslookupQualificationId); } //Get ExternalShiftSkills foreach (var item in externalShift.ShiftSkills) { var externalShiftSkill = db.ExternalShiftSkills.Where(a => a.Id == item.Id).FirstOrDefault(); externalShiftSkills.Add(externalShiftSkill.IndustrySkillsId); } //Get Shifts which are externaly BroadCasted. var shift = db.Shifts.Where(a => a.ExternalShiftBroadcastId == externalShift.Id && a.IsPublished == true && a.Employee == null && a.StartTime > dtNow).FirstOrDefault(); if (shift != null) { ShiftDTO objShift = MapperFacade.MapperConfiguration.Map <Shift, ShiftDTO>(shift); //Get Business Location details var businessLocation = db.BusinessLocations.Where(a => a.Id == objShift.BusinessLocationId).FirstOrDefault(); if (location.Address.PlaceLatitude != null && location.Address.PlaceLongitude != null) { //var LocationString = location.Split(','); //var userLocation = LocationString[0]; //var businessloc = db.BusinessLocations.Where(a => a.Address.Line1.Contains(userLocation)).ToList(); //New Location Lat, Long double lat1 = Convert.ToDouble(location.Address.PlaceLatitude); double long1 = Convert.ToDouble(location.Address.PlaceLongitude); //Business Lat,Long double lat2 = Convert.ToDouble(businessLocation.Address.PlaceLatitude); double long2 = Convert.ToDouble(businessLocation.Address.PlaceLongitude); //Get Distance between User and Businesslocation. var oUserLocaction = new GeoCoordinate(lat1, long1); var oBusinessLocation = new GeoCoordinate(lat2, long1); double distance = oUserLocaction.GetDistanceTo(oBusinessLocation); double DistanceInKM = distance / 1000; double selectedDistence = Convert.ToDouble(distancekm); if (DistanceInKM <= selectedDistence) { if (Check(userQuailificaions, externalShiftQuilificaion) && Check(userSkill, externalShiftSkills) == true) { var Externalshift = MapperFacade.MapperConfiguration.Map <ExternalShiftBroadcast, ExternalBroadcastDTO>(externalShift); Externalshift.Distance = DistanceInKM; ExternalBroadCastList.Add(Externalshift); } } } else { //User Lat, Long double lat1 = 0; double long1 = 0; if (userinfo.CurrentAddress.PlaceLatitude != null && userinfo.CurrentAddress.PlaceLongitude != null) { lat1 = Convert.ToDouble(userinfo.CurrentAddress.PlaceLatitude); long1 = Convert.ToDouble(userinfo.CurrentAddress.PlaceLongitude); } else { lat1 = Convert.ToDouble(userinfo.Address.PlaceLatitude); long1 = Convert.ToDouble(userinfo.Address.PlaceLongitude); } //Business Lat,Long double lat2 = Convert.ToDouble(businessLocation.Address.PlaceLatitude); double long2 = Convert.ToDouble(businessLocation.Address.PlaceLongitude); //Get Distance between User and Businesslocation. var oUserLocaction = new GeoCoordinate(lat1, long1); var oBusinessLocation = new GeoCoordinate(lat2, long1); double distance = oUserLocaction.GetDistanceTo(oBusinessLocation); double DistanceInKM = distance / 1000; double selectedDistence = Convert.ToDouble(distancekm); if (DistanceInKM <= selectedDistence) { if (Check(userQuailificaions, externalShiftQuilificaion) && Check(userSkill, externalShiftSkills) == true) { var Externalshift = MapperFacade.MapperConfiguration.Map <ExternalShiftBroadcast, ExternalBroadcastDTO>(externalShift); Externalshift.Distance = DistanceInKM; ExternalBroadCastList.Add(Externalshift); } } } } } } return(ExternalBroadCastList); }
public OpenShiftDTO GetFilteredOpenShifts(string JsonResult, string Distancce) { OpenShiftDTO model = new OpenShiftDTO(); //deserialize json Object of Address OpenShiftDTO location = new OpenShiftDTO(); location = new JavaScriptSerializer().Deserialize <OpenShiftDTO>(JsonResult); var email = HttpContext.Current.User.Identity.Name; var dtNow = WebUI.Common.Common.DateTimeNowLocal(); //Get the user info. var user = db.UserProfiles.FirstOrDefault(a => a.Email == email); // check if the user is an employee. var emp = user.Employees.FirstOrDefault(a => a.UserProfile.Id != null); if (emp != null) { model.OpenShiftsEmployee = OpenShiftEmployee(); model.OpenShiftList = (from shift in model.OpenShiftsEmployee.OpenShifts select new openShiftsList { Id = shift.Id, locationName = shift.BusinessLocationName, startTime = shift.StartTime, EndTime = shift.FinishTime, RoleName = shift.RoleName, date = shift.StartDay }).ToList(); //Check if user is also an external user as well. var exteruser = emp.UserProfile.IsRegisteredExternal; if (exteruser == true) { //Get Externalshifts model.ExternalShiftBroadCastEmpoyee = ExternalShiftEpmloyee(location, Distancce); foreach (var item in model.ExternalShiftBroadCastEmpoyee.ExternalShits) { var op = new openShiftsList(); op.Id = item.Id; op.RoleName = item.Shifts.FirstOrDefault().RoleName; op.locationName = item.BusinessLocationName; op.startTime = item.Shifts.FirstOrDefault().StartTime; op.EndTime = item.Shifts.FirstOrDefault().FinishTime; //Getting total hours TimeSpan time = op.EndTime.Subtract(op.startTime); op.totalhourse = time.TotalHours; //end op.date = item.Shifts.FirstOrDefault().StartDay; op.Description = item.Description; op.rate = item.Wage; //getting total pay int totalhours = Convert.ToInt32(op.totalhourse); op.totalPrice = op.rate * totalhours; op.IsExternalShift = true; op.Distance = Convert.ToInt32(item.Distance); model.OpenShiftList.Add(op); } } } else { //Get Externalshifts model.ExternalShiftBroadCastEmpoyee = ExternalShiftEpmloyee(location, Distancce); //add External shifts to list model.OpenShiftList = new List <openShiftsList>(); foreach (var item in model.ExternalShiftBroadCastEmpoyee.ExternalShits) { var op = new openShiftsList(); op.Id = item.Id; op.RoleName = item.Shifts.FirstOrDefault().RoleName; op.locationName = item.BusinessLocationName; op.startTime = item.Shifts.FirstOrDefault().StartTime; op.EndTime = item.Shifts.FirstOrDefault().FinishTime; //Getting total hours TimeSpan time = op.EndTime.Subtract(op.startTime); op.totalhourse = time.TotalHours; //end op.date = item.Shifts.FirstOrDefault().StartDay; op.Description = item.Description; op.rate = item.Wage; //getting total pay int totalhours = Convert.ToInt32(op.totalhourse); op.totalPrice = op.rate * totalhours; op.IsExternalShift = true; op.Distance = Convert.ToInt32(item.Distance); model.OpenShiftList.Add(op); } } return(model); }