Esempio n. 1
0
        public List <GETEquipmentListVM> getEquipmentListByJobsite(long jobsiteAuto, int User)
        {
            List <GETEquipmentListVM> result = new List <GETEquipmentListVM>();

            if (jobsiteAuto == 0)
            {
                return(result);
            }

            using (var dataEntitiesShared = new DAL.SharedContext())
            {
                result = (from eqmt in dataEntitiesShared.EQUIPMENT
                          join lu_mmta in dataEntitiesShared.LU_MMTA
                          on eqmt.mmtaid_auto equals lu_mmta.mmtaid_auto
                          join model in dataEntitiesShared.MODEL
                          on lu_mmta.model_auto equals model.model_auto
                          join make in dataEntitiesShared.MAKE
                          on lu_mmta.make_auto equals make.make_auto
                          where eqmt.crsf_auto == jobsiteAuto
                          select new GETEquipmentListVM
                {
                    equipmentid_auto = eqmt.equipmentid_auto,
                    serialno = eqmt.serialno,
                    unitno = eqmt.unitno,
                    model_auto = model.model_auto,
                    modeldesc = model.modeldesc,
                    makedesc = make.makedesc
                }).ToList();
            }
            var accessible = new BLL.Core.Domain.UserAccess(new SharedContext(), User).getAccessibleEquipments().Select(m => m.equipmentid_auto);

            return(result.Where(m => accessible.Any(k => k == m.equipmentid_auto)).ToList());
        }
Esempio n. 2
0
        public List <int> getEquipmentIdsByCustomer(long customerAuto, System.Security.Principal.IPrincipal User)
        {
            var _access = new BLL.Core.Domain.UserAccess(new SharedContext(), User);
            var accessibleJobsiteIds = _access.getAccessibleJobsites().Where(m => m.customer_auto == customerAuto).Select(m => m.crsf_auto);

            return(_access.getAccessibleEquipments().Where(m => accessibleJobsiteIds.Any(k => m.crsf_auto == k)).Select(m => m.equipmentid_auto).ToList().LongNullableToInt());
        }
Esempio n. 3
0
        public List <EquipmentListVM> getCompatibleEquipmentForImplementByJobsite(long jobsiteId, int getAuto, System.Security.Principal.IPrincipal User)
        {
            List <EquipmentListVM> result = new List <EquipmentListVM>();

            using (var context = new DAL.GETContext())
            {
                // Get implement id
                long implementAuto = context.GET.Find(getAuto).implement_auto ?? 0;
                if (implementAuto == 0)
                {
                    return(result);
                }

                // Find valid models for implement.
                var validModels = context.GET_IMPLEMENT_MAKE_MODEL.Where(w => w.implement_auto == implementAuto)
                                  .Select(s => new
                {
                    equipmentModel = s.model_auto
                }).ToList();

                // Find all equipment at the specified jobsite for which the user has permissions to access.
                var allEquipmentAtJobsite = new BLL.Core.Domain.UserAccess(new SharedContext(), User)
                                            .getAccessibleEquipments().Where(e => e.crsf_auto == jobsiteId)
                                            .Select(s => new
                {
                    equipmentId       = s.equipmentid_auto,
                    equipmentSerialNo = s.serialno,
                    equipmentSMU      = s.currentsmu.Value,
                    equipmentModel    = s.LU_MMTA.model_auto
                }).ToList();

                // Filter results by valid models for the specified jobsite.
                for (int i = 0; i < allEquipmentAtJobsite.Count; i++)
                {
                    for (int j = 0; j < validModels.Count; j++)
                    {
                        if (allEquipmentAtJobsite[i].equipmentModel == validModels[j].equipmentModel)
                        {
                            result.Add(new EquipmentListVM
                            {
                                equipmentId       = allEquipmentAtJobsite[i].equipmentId,
                                equipmentSerialNo = allEquipmentAtJobsite[i].equipmentSerialNo,
                                equipmentSMU      = allEquipmentAtJobsite[i].equipmentSMU
                            });
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
        public async Task <EditUserModel> GetUserDetails(long userId, bool showPassword)
        {
            EditUserModel returnUser;
            var           userEntity = await _context.USER_TABLE.Where(u => u.user_auto == userId).FirstOrDefaultAsync();

            List <AccessCustomerIdsForUserEditModel> customerIds = new List <AccessCustomerIdsForUserEditModel>();
            List <JobRolesForUserEditModel>          jobRoles    = await _context.USER_GROUP_ASSIGN.Where(j => j.user_auto == userId).Select(j => new JobRolesForUserEditModel()
            {
                id       = j.group_auto,
                itemName = j.USER_GROUP.groupname
            }).ToListAsync();

            if (userEntity == null)
            {
                return(null);
            }
            //var accessMap = await _context.UserAccessMaps.Where(m => m.user_auto == userId)
            //    .OrderByDescending(m => m.DealershipId).ThenByDescending(m => m.customer_auto)
            //    .ThenBy(m => m.AccessLevelTypeId).FirstOrDefaultAsync();

            var highestAccessCategory = new BLL.Core.Domain.UserAccess(new SharedContext(), (int)userId).getHighestCategoryAccess();

            //if(highestAccessCategory == BLLDomain.AccessCategory.SupportTeam)
            //{
            //    customerIds = await _context.UserAccessMaps.Where(c => c.user_auto == userId).Where(c => c.customer_auto != null).Select(c => new AccessCustomerIdsForUserEditModel()
            //    {
            //        id = c.customer_auto == null ? 0 : (int) c.customer_auto,
            //        itemName = c.CUSTOMER == null ? "" : c.CUSTOMER.cust_name
            //    }).ToListAsync();
            //}

            returnUser = new EditUserModel()
            {
                AccessTypeId         = (int)highestAccessCategory,
                CustomerId           = 0, //accessMap.customer_auto,
                DealershipId         = 0, //accessMap.DealershipId,
                Email                = userEntity.email,
                UserName             = userEntity.userid,
                GetEnabled           = DoesAccessTypeAllowGET(userEntity.ApplicationAccess == null ? 0 : (int)userEntity.ApplicationAccess),
                UndercarriageEnabled = DoesAccessTypeAllowUndercarriage(userEntity.ApplicationAccess == null ? 0 : (int)userEntity.ApplicationAccess),
                Id   = userEntity.user_auto,
                Name = userEntity.username,
                AccessCustomerIds = customerIds,
                JobRoles          = jobRoles,
                Password          = showPassword ? userEntity.passwd : ""
            };

            return(returnUser);
        }
Esempio n. 5
0
        public List <GETEquipmentListVM> getEquipmentListByCustomer(long customerAuto, System.Security.Principal.IPrincipal User)
        {
            List <GETEquipmentListVM> result = new List <GETEquipmentListVM>();

            if (customerAuto == 0)
            {
                return(result);
            }

            using (var dataEntitiesShared = new DAL.SharedContext())
            {
                result = (from eqmt in dataEntitiesShared.EQUIPMENT
                          join crsf in dataEntitiesShared.CRSF
                          on eqmt.crsf_auto equals crsf.crsf_auto
                          join customer in dataEntitiesShared.CUSTOMER
                          on crsf.customer_auto equals customer.customer_auto
                          join lu_mmta in dataEntitiesShared.LU_MMTA
                          on eqmt.mmtaid_auto equals lu_mmta.mmtaid_auto
                          join model in dataEntitiesShared.MODEL
                          on lu_mmta.model_auto equals model.model_auto
                          join make in dataEntitiesShared.MAKE
                          on lu_mmta.make_auto equals make.make_auto
                          where customer.customer_auto == customerAuto
                          select new GETEquipmentListVM
                {
                    equipmentid_auto = eqmt.equipmentid_auto,
                    serialno = eqmt.serialno,
                    unitno = eqmt.unitno,
                    modeldesc = model.modeldesc,
                    makedesc = make.makedesc,
                    customer_auto = customer.customer_auto,
                    cust_name = customer.cust_name
                }).ToList();
            }
            var accessible = new BLL.Core.Domain.UserAccess(new SharedContext(), User).getAccessibleEquipments().Select(m => m.equipmentid_auto);

            return(result.Where(m => accessible.Any(k => k == m.equipmentid_auto)).ToList());
        }
Esempio n. 6
0
        /// <summary>
        /// Returns some general details of all user accounts in the database which the user id given has access to see.
        /// Used to populate the user table in the team administration page.
        /// </summary>
        /// <param name="userId">User ID used to determine which accounts to return. </param>
        /// <returns></returns>

        /*public async Task<List<UserOverviewModel>> GetAllUsersForUser(long userId)
         * {
         *  List<UserOverviewModel> returnList = new List<UserOverviewModel>();
         *  List<long> userIds = new List<long>();
         *  var userAccess = await _context.UserAccessMaps.Where(m => m.user_auto == userId).ToListAsync();
         *
         *  foreach(var access in userAccess)
         *  {
         *      if(access.AccessLevelTypeId == (int) UserAccessTypes.GlobalAdministrator)
         *      {
         *          userIds.AddRange(_context.USER_TABLE.Select(u => u.user_auto));
         *      } else if(access.AccessLevelTypeId == (int) UserAccessTypes.DealershipAdministrator)
         *      {
         *          userIds.AddRange(_context.UserAccessMaps.Where(m => m.DealershipId == access.DealershipId).Where(m=> m.user_auto != null).Select(u => (long)u.user_auto));
         *          var customerIds = _context.CUSTOMER.Where(c => c.DealershipId == access.DealershipId).Select(c => c.customer_auto);
         *          foreach(var customerId in customerIds)
         *          {
         *              try
         *              {
         *                  userIds.AddRange(_context.UserAccessMaps.Where(m => m.customer_auto == customerId).Where(m => m.user_auto != null).Select(u => (long)u.user_auto).ToList());
         *              } catch (Exception e)
         *              {
         *                  //
         *              }
         *
         *          }
         *      } else if(access.AccessLevelTypeId == (int) UserAccessTypes.CustomerAdministrator)
         *      {
         *          userIds.AddRange(_context.UserAccessMaps.Where(m => m.customer_auto == access.customer_auto)
         *              .Where(m => m.AccessLevelTypeId == (int)UserAccessTypes.CustomerUser || m.AccessLevelTypeId == (int)UserAccessTypes.CustomerAdministrator)
         *              .Where(m => m.user_auto != null).Select(u => (long)u.user_auto));
         *      }
         *  }
         *
         *  foreach(var user in userIds.Distinct())
         *  {
         *      var userAccessLevel = await _context.UserAccessMaps.Where(m => m.user_auto == user).OrderByDescending(m => m.DealershipId).ThenByDescending(m => m.customer_auto).ThenBy(m => m.AccessLevelTypeId).FirstOrDefaultAsync();
         *      string name;
         *      if (userAccessLevel != null)
         *      {
         *          if (userAccessLevel.AccessLevelTypeId == (int)UserAccessTypes.DealershipAdministrator || userAccessLevel.AccessLevelTypeId == (int)UserAccessTypes.DealershipUser)
         *              name = userAccessLevel.Dealership.Name;
         *          else if (userAccessLevel.AccessLevelTypeId == (int)UserAccessTypes.CustomerAdministrator || userAccessLevel.AccessLevelTypeId == (int)UserAccessTypes.CustomerUser)
         *              name = userAccessLevel.CUSTOMER.cust_name;
         *          else
         *              name = "";
         *          returnList.AddRange(_context.USER_TABLE.Where(u => u.user_auto == user).Select(u => new UserOverviewModel()
         *          {
         *              Email = u.email,
         *              UserId = u.user_auto,
         *              FullName = u.username,
         *              UserName = u.userid,
         *              TeamName = name,
         *              Access = userAccessLevel.AccessLevelType.Name,
         *              Disabled = u.suspended
         *          }));
         *      }
         *  }
         *
         *  return returnList.OrderBy(l => l.Disabled).ThenBy(l => l.UserName).ToList();
         * }
         */
        /// <summary>
        /// Returns some general details of all user accounts in the database which the user id given has access to see.
        /// Used to populate the user table in the team administration page.
        /// </summary>
        /// <param name="userId">User ID used to determine which accounts to return. </param>
        /// <returns></returns>
        public async Task <List <UserOverviewModel> > GetAllUsersForUser(long userId)
        {
            List <UserOverviewModel> returnList = new List <UserOverviewModel>();

            var users = await Task.Run(() => { return(new BLLDomain.UserAccess(new SharedContext(), userId.LongNullableToInt()).getAccessibleUsers()); });

            foreach (var user in users.ToList())
            {
                var supportTeams = new BLLDomain.UserAccess(new SharedContext(), user.user_auto.LongNullableToInt()).getAccessibleSupportTeams();
                if (supportTeams.Count() > 0)
                {
                    returnList.Add(new UserOverviewModel
                    {
                        Access   = "Support Team",
                        Disabled = user.suspended,
                        UserId   = user.user_auto,
                        Email    = user.email,
                        UserName = user.userid,
                        TeamName = string.Join(",", supportTeams.Select(m => m.Name).ToArray()),
                        FullName = user.username
                    });
                    continue;
                }
                var dealerGroups = new BLLDomain.UserAccess(new SharedContext(), user.user_auto.LongNullableToInt()).getAccessibleDealerGroups();
                if (dealerGroups.Count() > 0)
                {
                    returnList.Add(new UserOverviewModel
                    {
                        Access   = "Dealer Group",
                        Disabled = user.suspended,
                        UserId   = user.user_auto,
                        Email    = user.email,
                        UserName = user.userid,
                        TeamName = string.Join(",", dealerGroups.Select(m => m.Name).ToArray()),
                        FullName = user.username
                    });
                    continue;
                }

                var dealers = new BLLDomain.UserAccess(new SharedContext(), user.user_auto.LongNullableToInt()).getAccessibleDealers();
                if (dealers.Count() > 0)
                {
                    returnList.Add(new UserOverviewModel
                    {
                        Access   = "Dealer",
                        Disabled = user.suspended,
                        UserId   = user.user_auto,
                        Email    = user.email,
                        UserName = user.userid,
                        TeamName = string.Join(",", dealers.Select(m => m.Name).ToArray()),
                        FullName = user.username
                    });
                    continue;
                }

                var customers = new BLLDomain.UserAccess(new SharedContext(), user.user_auto.LongNullableToInt()).getAccessibleCustomers();
                if (customers.Count() > 0)
                {
                    returnList.Add(new UserOverviewModel
                    {
                        Access   = "Customer",
                        Disabled = user.suspended,
                        UserId   = user.user_auto,
                        Email    = user.email,
                        UserName = user.userid,
                        TeamName = string.Join(",", customers.Select(m => m.cust_name).ToArray()),
                        FullName = user.username
                    });
                    continue;
                }

                var jobsites = new BLLDomain.UserAccess(new SharedContext(), user.user_auto.LongNullableToInt()).getAccessibleJobsites();
                if (jobsites.Count() > 0)
                {
                    returnList.Add(new UserOverviewModel
                    {
                        Access   = "Jobsite",
                        Disabled = user.suspended,
                        UserId   = user.user_auto,
                        Email    = user.email,
                        UserName = user.userid,
                        TeamName = string.Join(",", jobsites.Select(m => m.site_name).ToArray()),
                        FullName = user.username
                    });
                    continue;
                }

                var equipemnts = new BLLDomain.UserAccess(new SharedContext(), user.user_auto.LongNullableToInt()).getAccessibleEquipments();
                if (equipemnts.Count() > 0)
                {
                    returnList.Add(new UserOverviewModel
                    {
                        Access   = "Equipment",
                        Disabled = user.suspended,
                        UserId   = user.user_auto,
                        Email    = user.email,
                        UserName = user.userid,
                        TeamName = string.Join(",", equipemnts.Select(m => m.serialno).ToArray()),
                        FullName = user.username
                    });
                    continue;
                }
                returnList.Add(new UserOverviewModel
                {
                    Access   = "No Access",
                    Disabled = user.suspended,
                    UserId   = user.user_auto,
                    Email    = user.email,
                    UserName = user.userid,
                    TeamName = "",
                    FullName = user.username
                });
            }

            return(returnList.OrderBy(l => l.Disabled).ThenBy(l => l.UserName).ToList());
        }