Exemple #1
0
        /// <summary>
        /// Returns a list of all customers that belong to a given dealership.
        /// </summary>
        /// <param name="dealershipId"></param>
        /// <returns>A list of customer objects. Each object contains the customer's id, name, contactEmail, isActive and jobsiteCount. </returns>

        public List <BasicCustomerDataSet> getListOfCustomersForDealership(int dealershipId, System.Security.Principal.IPrincipal User)
        {
            var customers = new BLL.Core.Domain.UserAccess(new SharedContext(), User).getAccessibleCustomers();

            using (var context = new SharedContext())
            {
                return(customers.OrderBy(c => c.cust_name).Where(c => c.DealershipId == dealershipId)
                       .Select(c => new BasicCustomerDataSet
                {
                    id = c.customer_auto,
                    name = c.cust_name,
                    contactEmail = c.cust_email,
                    isActive = c.active,
                    jobsiteCount = context.CRSF.Where(j => j.customer_auto == c.customer_auto).Count()
                }).ToList());
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns some general details of dealerships the given user id has access to
        /// </summary>
        /// <param name="userId">User ID used to determine which dealerships to return. </param>
        /// <returns></returns>
        public async Task <List <DealershipOverviewModel> > GetAllDealershipsForUser(long userId)
        {
            List <DealershipOverviewModel> returnList = new List <DealershipOverviewModel>();
            List <long> dealershipIds = new List <long>();
            var         userAccess    = await _context.UserAccessMaps.Where(m => m.user_auto == userId).ToListAsync();

            var dealers = new BLL.Core.Domain.UserAccess(new SharedContext(), userId.LongNullableToInt()).getAccessibleDealers().Select(m => new DealershipOverviewModel {
                DealershipId = m.DealershipId, DealershipName = m.Name
            }).ToList();

            foreach (var dealer in dealers)
            {
                dealer.BrandedStyles = _undercarriageContext.DealershipBranding.Where(m => m.DealershipId == dealer.DealershipId).Select(b => new BrandedStyleModel()
                {
                    Id   = b.Id,
                    Name = b.Name
                }).ToList();
            }

            return(dealers.OrderBy(m => m.DealershipName).ToList());
        }