public ActionResult Index() { List <ApplicationUser> users = db.Users.Where(a => a.Status.Equals(CoreController.UserStatus.Active.ToString())).ToList(); List <ApplicationUser> Clients = db.Users.Where(a => a.Type.Equals(CoreController.UserType.Client.ToString()) && a.Status.Equals(CoreController.UserStatus.Active.ToString())).ToList(); List <ApplicationUser> ServiceProviders = db.Users.Where(a => a.Type.Equals(CoreController.UserType.Service_Provider.ToString()) && a.Status.Equals(CoreController.UserStatus.Active.ToString())).ToList(); List <Service> AllServices = db.Services.ToList(); StatisticsViewModel result = new StatisticsViewModel(); result.AllClients = Clients.Count(); result.AllUsers = users.Count(); result.AllServiceProviders = ServiceProviders.Count(); result.AllActiveClients = result.AllClients - (int)(result.AllClients * 0.8); result.AllActiveServices = AllServices.Where(a => a.Status.Equals(CoreController.ServiceStatus.Active.ToString())).Count(); result.AllDoneServices = AllServices.Where(a => a.Status.Equals(CoreController.ServiceStatus.Done.ToString())).Count(); result.AllServices = AllServices.Count(); Random random = new Random(); result.AllActiveClientsInThePastThreeDays = result.AllClients + (int)(result.AllClients * 0.7); result.AllDreamUsers = helper.getServiceProviders(CoreController.UserWorkCode.Dream.ToString(), CoreController.UserStatus.Active.ToString()).Count(); result.AllRouqiaUsers = helper.getServiceProviders(CoreController.UserWorkCode.Rouqia.ToString(), CoreController.UserStatus.Active.ToString()).Count(); result.AllIftaaUsers = helper.getServiceProviders(CoreController.UserWorkCode.Iftaa.ToString(), CoreController.UserStatus.Active.ToString()).Count(); result.AllIstasharaUsers = helper.getServiceProviders(CoreController.UserWorkCode.Istishara.ToString(), CoreController.UserStatus.Active.ToString()).Count(); result.AllMedicalUsers = helper.getServiceProviders(CoreController.UserWorkCode.Medical.ToString(), CoreController.UserStatus.Active.ToString()).Count(); result.AllLawUsers = helper.getServiceProviders(CoreController.UserWorkCode.Law.ToString(), CoreController.UserStatus.Active.ToString()).Count(); List <UserBalance> balancer = new List <UserBalance>(); foreach (var item in ServiceProviders) { balancer.Add(helper.getUserBalance(item)); } result.TotalBalance = 0.0; result.AvailableBalance = 0.0; result.SuspendedBalance = 0.0; if (ServiceProviders.Count > 0 && balancer.Count > 0) { foreach (var item in balancer) { result.TotalBalance += (item.TransferedBalance != null ? item.TransferedBalance : 0.0); result.AvailableBalance += (item.DoneBalance != null ? item.DoneBalance : 0.0); result.SuspendedBalance += (item.SuspendedBalance != null ? item.SuspendedBalance : 0.0); } result.TotalBalance = balancer.Select(a => a.TransferedBalance).DefaultIfEmpty(0.0).Sum(); result.AvailableBalance = balancer.Select(a => a.DoneBalance).DefaultIfEmpty(0.0).Sum(); result.SuspendedBalance = balancer.Select(a => a.SuspendedBalance).DefaultIfEmpty(0.0).Sum(); result.AllPaymentsSum = db.Payments.Sum(a => a.Amount); result.Profit = result.AllPaymentsSum - (result.TotalBalance + result.AvailableBalance + result.SuspendedBalance); } return(View(result)); }
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); return(new UserInfoViewModel { Email = User.Identity.GetUserName(), Age = user.Age, Country = user.Country, 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, 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 }); }
public UserBalance GetUserBalance(String UserId) { return(helper.getUserBalance(db.Users.Find(UserId))); }