public ServicePathViewModel GetServicePathForProvider(String id, int pathId) { List <Service> services = helper.getUserServices(id); List <Service> activeSerives = helper.getServicesFiltered(services, CoreController.ServiceStatus.Active.ToString()); List <Service> doneServices = helper.getServicesFiltered(services, CoreController.ServiceStatus.Done.ToString()); double speed = UserHelperLibrary.ServiceProviderSpeed(helper.findUser(id), doneServices.Count); speed = speed < 1 ? 1 : speed; List <ServicePath> paths = db.ServicePaths.Where(a => a.id.Equals(pathId)).ToList(); if (paths.Count == 0) { paths = db.ServicePaths.Where(a => a.ServiceProviderId.Equals(null) && a.Enabled).ToList(); } List <ServicePathViewModel> result = new List <ServicePathViewModel>(); foreach (var item in paths) { int numOfOpenDreams = activeSerives.Where(a => a.ServicePathId.Equals(item.id)).Count(); ServicePathViewModel temp = new ServicePathViewModel(); temp.id = item.id; temp.Cost = item.Cost; temp.Name = item.Name; temp.NumberOfPeopleWaiting = numOfOpenDreams; temp.AvgWaitingTime = UserHelperLibrary.getWaitingTimeMessage(Double.Parse(speed.ToString()), Double.Parse(numOfOpenDreams.ToString())).Replace("Your average waiting time is ", ""); result.Add(temp); } return(result[0]); }
public ServiceViewModel getMapping(Service service) { List <Service> allService = db.Services.Where(a => a.ServiceProviderId.Equals(service.ServiceProviderId) && a.ServicePathId.Equals(service.ServicePathId) && a.Status.Equals(CoreController.ServiceStatus.Active.ToString())).ToList(); List <Service> services = helper.getUserServices(service.ServiceProviderId); List <Service> activeSerives = helper.getServicesFiltered(services, CoreController.ServiceStatus.Active.ToString()); List <Service> doneServices = helper.getServicesFiltered(services, CoreController.ServiceStatus.Done.ToString()); double speed = UserHelperLibrary.ServiceProviderSpeed(helper.findUser(service.ServiceProviderId), doneServices.Count); AccountController accountCont = new AccountController(); ServiceViewModel result = new ServiceViewModel(); result.Comments = service.Comments; result.Country = service.Country; result.CreationDate = service.CreationDate; result.Creator = service.Creator; result.Description = service.Description; result.CreatorId = service.CreatorId; result.DidYouExorcism = service.DidYouExorcism; result.DreamDate = service.DreamDate; result.Explanation = service.Explanation; result.ExplanationDate = service.ExplanationDate; result.HaveYouPrayedBeforeTheDream = service.HaveYouPrayedBeforeTheDream; result.id = service.id; result.IsThereWakefulness = service.IsThereWakefulness; result.JobStatus = service.JobStatus; result.KidsStatus = service.KidsStatus; result.LastModificationDate = service.LastModificationDate; result.Modifier = service.Modifier; result.ModifierId = service.ModifierId; result.Name = service.Name; result.numberOfLikes = service.numberOfLikes; result.numberOfViews = service.numberOfViews; result.PrivateService = service.PrivateService; result.PrivateServicePrice = service.PrivateServicePrice; result.PublicServiceAction = service.PublicServiceAction; result.RegligionStatus = service.RegligionStatus; result.ServicePathId = service.ServicePathId; result.ServiceProvider = service.ServiceProvider; result.ServiceProviderId = service.ServiceProviderId; result.Sex = service.Sex; result.SocialStatus = service.SocialStatus; result.Status = service.Status; result.UserWork = service.UserWork; result.UserWorkId = service.UserWorkId; result.ServicePath = service.ServicePath; result.NumberOfAllPeopleWaiting = allService.Count > 0 ? allService.Count : 0; result.NumberOfRemainingPeople = allService.Count > 0 ? allService.Where(a => a.CreationDate.CompareTo(service.CreationDate) < 0).Count() : 0; result.AvgWaitingTime = UserHelperLibrary.getWaitingTimeMessage(Double.Parse(speed.ToString()), Double.Parse(result.NumberOfRemainingPeople.ToString())).Replace("Your average waiting time is ", ""); return(result); }
public double GetUserSpeed(String UserId) { List <Service> services = helper.getUserServices(UserId); List <Service> activeSerives = helper.getServicesFiltered(services, CoreController.ServiceStatus.Active.ToString()); List <Service> doneServices = helper.getServicesFiltered(services, CoreController.ServiceStatus.Done.ToString()); double speed = UserHelperLibrary.ServiceProviderSpeed(helper.findUser(UserId), doneServices.Count); return(speed); }
public UserInfoViewModel getInfoMapping(ApplicationUser user) { List <Service> services = helper.getUserServices(user.Id); List <Service> activeSerives = helper.getServicesFiltered(services, CoreController.ServiceStatus.Active.ToString()); List <Service> doneServices = helper.getServicesFiltered(services, CoreController.ServiceStatus.Done.ToString()); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); List <UserWorkBinding> userWork = db.UserWorkBindings.Where(a => a.UserId.Equals(user.Id)).Include("UserWork").ToList(); double speed = UserHelperLibrary.ServiceProviderSpeed(helper.findUser(user.Id), doneServices.Count); double avg = UserHelperLibrary.ServiceProviderAvgServices(helper.findUser(user.Id), services.Count); UserBalance balance = helper.getUserBalance(user); DateTime dateOfTheLastService = doneServices.Count > 0? doneServices.OrderBy(a => a.LastModificationDate).FirstOrDefault().LastModificationDate:user.CreationDate; return(new UserInfoViewModel { Email = user.Email, Age = user.Age, Country = user.Country, CreationDate = user.CreationDate, JobDescription = user.JobDescription, JoiningDate = user.JoiningDate, Name = user.Name, MartialStatus = user.MartialStatus, PictureId = user.PictureId, Sex = user.Sex, Status = user.Status, Type = user.Type, phoneNumber = user.PhoneNumber, PersonalDescription = user.PersonalDescription, FireBaseId = user.FireBaseId, Id = user.Id, HasRegistered = user.verifiedInterpreter, UserWorks = userWork.Select(a => a.UserWork).ToList(), NumberOfActiveServices = activeSerives.Count(), NumberOfDoneServices = doneServices.Count(), Speed = speed < 1 ? 1 : speed, AvgServicesInOneDay = avg == 0 ? 1 : avg, UserRoles = userManager.GetRoles(user.Id).ToList(), SocialStatus = user.SocialState, ImageUrl = user.imageUrl, SocialToken = user.SocialToken, TotalBalance = balance.TransferedBalance, AvailableBalance = balance.DoneBalance, SuspendedBalance = balance.SuspendedBalance, CompetitionBalance = balance.CompetitionBalance, PointsBalance = user.PointsBalance, UserSpecialCode = user.UserSpecialCode, UserName = user.UserName, VerifiedUser = user.verifiedInterpreter, ServiceProviderPoints = user.ServiceProviderPoints, dateOfLastService = dateOfTheLastService, rank = user.rank }); }
public List <CompetitionResult> getFastest(List <ApplicationUser> users, DateTime startDate, bool tempResult) { List <CompetitionResult> result = new List <CompetitionResult>(); foreach (var user in users) { List <Service> services = helper.getUserServices(user.Id, startDate); List <Service> activeSerives = helper.getServicesFiltered(services, CoreController.ServiceStatus.Active.ToString()); List <Service> doneServices = helper.getServicesFiltered(services, CoreController.ServiceStatus.Done.ToString()); double speed = UserHelperLibrary.ServiceProviderSpeed(doneServices.Count, startDate); CompetitionResult temp = new CompetitionResult { Speed = speed < 1 ? 1 : speed, ServiceProviderId = user.Id, NumberOfActiveServices = activeSerives.Count(), NumberOfDoneServices = doneServices.Count(), LastModificationDate = DateTime.Now, CreationDate = DateTime.Now, TotalBalance = 0, SuspendedBalance = 0, AvailableBalance = 0, Rating = 0, AvgServicesInOneDay = 0 //TotalBalance = balance.TransferedBalance, //AvailableBalance = balance.DoneBalance, //SuspendedBalance = balance.SuspendedBalance, }; if (tempResult) { temp.ServiceProvider = user; } result.Add(temp); //db.CompetitionResults.Add(temp); } result = result.OrderByDescending(a => a.Speed).ToList(); int j = 1; foreach (var item in result) { item.rank = j; j++; } return(result); //return InsertionSortNew(result); }
public ServiceViewModel getMappingv2(Service service) { List <Service> allService = db.Services.Where(a => a.ServiceProviderId.Equals(service.ServiceProviderId) && a.ServicePathId.Equals(service.ServicePathId) && a.Status.Equals(CoreController.ServiceStatus.Active.ToString())).ToList(); List <Service> services = helper.getUserServices(service.ServiceProviderId); List <Service> activeSerives = helper.getServicesFiltered(services, CoreController.ServiceStatus.Active.ToString()); List <Service> doneServices = helper.getServicesFiltered(services, CoreController.ServiceStatus.Done.ToString()); double speed = UserHelperLibrary.ServiceProviderSpeed(helper.findUser(service.ServiceProviderId), doneServices.Count); speed = speed < 1 ? 1 : speed; double avg = UserHelperLibrary.ServiceProviderAvgServices(helper.findUser(service.ServiceProviderId), services.Count); AccountController accountCont = new AccountController(); ServiceViewModel result = new ServiceViewModel(); result.Country = service.Country; result.CreationDate = service.CreationDate; result.Creator = service.Creator; result.Description = service.Description; result.CreatorId = service.CreatorId; result.Id = service.id; result.Name = service.Name; result.numberOfLikes = service.numberOfLikes; result.numberOfViews = service.numberOfViews; result.PrivateService = service.PrivateService; result.PrivateServicePrice = service.PrivateServicePrice; result.PublicServiceAction = service.PublicServiceAction; result.ServicePathId = service.ServicePathId; result.ServiceProvider = service.ServiceProvider; result.ServiceProviderId = service.ServiceProviderId; result.Status = service.Status; result.UserWork = service.UserWork; result.UserWorkId = service.UserWorkId; result.ServicePath = service.ServicePath; result.ServiceProviderNewDate = service.ServiceProviderNewDate; result.ServiceProviderSpeed = speed; result.ServiceProviderAvgServices = avg == 0 ? 1 : avg; return(result); }