Пример #1
0
        public PagedResultsDto GetAllActiveFeatures(long adminId, int page, int pageSize, string role)
        {
            var user = _userService.Find(adminId);

            if (user == null)
            {
                throw new ValidationException(ErrorCodes.UserNotFound);
            }
            if (user.IsDeleted)
            {
                throw new ValidationException(ErrorCodes.UserDeleted);
            }
            if (!user.IsActive)
            {
                throw new ValidationException(ErrorCodes.UserDeactivated);
            }
            int featuresCount          = 0;
            List <FeatureDto> features = null;

            if (role == Enums.RoleType.Admin.ToString())
            {
                featuresCount = _featureService.Query(x => !x.IsDeleted && x.CreationBy == adminId).Select().Count();
                features      = Mapper.Map <List <FeatureDto> >(_featureService.GetAllActiveFeaturesAdminId(adminId, page, pageSize));
                //PagedResultsDto results = new PagedResultsDto
                //{
                //    TotalCount = featuresCount,
                //    Data = features
                //};
                //return results;
            }
            else if (role == Enums.RoleType.Room.ToString())
            {
                var room = _roomService.Find(adminId);
                featuresCount = _featureService.Query(x => !x.IsDeleted && x.CreationBy == room.AdminId).Select().Count();
                //features = Mapper.Map<List<FeatureDto>>(_featureService.GetAllActiveFeaturesAdminId(room.AdminId, page, pageSize));
                features = Mapper.Map <List <Feature>, List <FeatureDto> >(_featureService.GetAllActiveFeaturesAdminId(room.AdminId, page, pageSize), opt =>
                {
                    opt.BeforeMap((src, dest) =>
                    {
                        foreach (Feature feature  in src)
                        {
                            feature.Restaurants = feature.Restaurants.Where(x => x.IsActive && !x.IsDeleted)
                                                  .ToList();
                        }
                    }
                                  );
                });
            }

            PagedResultsDto results = new PagedResultsDto
            {
                TotalCount = featuresCount,
                Data       = features
            };

            return(results);
        }