Beispiel #1
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            var response = await _identityClient.UpdateUserInfoAsync(new UserDto
            {
                Id          = User.Claims.FirstOrDefault(x => x.Type.Contains("nameidentifier")).Value,
                Email       = model.NameEmail ?? "",
                Username    = model.NameEmail ?? "",
                PhoneNumber = model.Phone ?? ""
            });

            if (!response.HasErrors)
            {
                ViewBag.Role = User.Claims.FirstOrDefault(x => x.Type.Contains("role")).Value;
                AdvertFilter filter = new AdvertFilter
                {
                    CurrentPage = 1, Size = 20, UserId = User.Claims.FirstOrDefault(x => x.Type.Contains("nameidentifier")).Value
                };
                var advert_response = await _advertApiClient.GetAdvertsByFilterAsync(filter);

                ViewBag.Adverts     = advert_response.Data;
                ViewBag.EditSuccess = true;
                var cats = await _categoryApiClient.GetCategoriesAsync();

                ViewBag.Categories = cats.Data;
                model.NameEmail    = (model.NameEmail == null) ? "" : model.NameEmail;
                model.Phone        = (model.Phone == null) ? "" : model.Phone;
                return(View(model));
            }
            else
            {
                return(View("Error", new ErrorViewModel {
                    RequestId = response.Errors.FirstOrDefault()
                }));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Login()
        {
            var cats = await _categoryApiClient.GetCategoriesAsync();

            string userId = User.Claims.FirstOrDefault(x => x.Type.Contains("nameidentifier")).Value;

            ViewBag.Role = User.Claims.FirstOrDefault(x => x.Type.Contains("role")).Value;


            var user = await _identityClient.GetUserInfoAsync(userId);

            var user_dto = user.Data;

            LoginViewModel model = new LoginViewModel {
                NameEmail = user_dto.Email,
                Phone     = user_dto.PhoneNumber ?? ""
            };



            AdvertFilter filter = new AdvertFilter {
                CurrentPage = 1, Size = 20, UserId = userId
            };
            var response = await _advertApiClient.GetAdvertsByFilterAsync(filter);

            ViewBag.Adverts = response.Data;

            ViewBag.Categories = cats.Data;
            return(View(model));
        }
Beispiel #3
0
 private IQueryable <Advert> GetAllAdverts(AdvertFilter model)
 {
     return(Context.Adverts
            .Include("FilesMetaData")
            .SelectSatisfying(new AdvertTypeSpecification(model.AdvertType))
            .SelectSatisfying(new AdvertWithPhotoSpecification(model.OnlyWithPhoto))
            .SelectSatisfying(new AdvertCostSpecification(model.MinCost, model.MaxCost)));
 }
 public async Task <IActionResult> GetByFilterAsync([FromBody] AdvertFilter filter)
 {
     if (filter.CurrentPage < 1)
     {
         throw new Exception($"{nameof(filter)} Page must be more than 0");
     }
     return(ApiResult(await _advertManager.GetAdvertsByFilterAsync(filter)));
 }
Beispiel #5
0
 private IQueryable <Advert> GetRooms(AdvertFilter model)
 {
     return(GetAllAdverts(model)
            .OfType <Room>()
            .SelectSatisfying(new FloorSpecification(model.FloorFilter))
            .SelectSatisfying(new RoomCountSpecification(model.RoomCountFilter))
            .SelectSatisfying(new FloorCountSpecification(model.FloorCountFilter))
            .SelectSatisfying(new ObjectTypeSpecification(model.ObjectType)));
 }
Beispiel #6
0
 private IQueryable <Advert> GetApartments(AdvertFilter model)
 {
     return(GetAllAdverts(model)
            .Where(x => x.RealtyType == RealtyType.Apartment)
            .OfType <Apartment>()
            .SelectSatisfying(new FloorSpecification(model.FloorFilter))
            .SelectSatisfying(new RoomCountSpecification(model.RoomCountFilter))
            .SelectSatisfying(new FloorCountSpecification(model.FloorCountFilter))
            .SelectSatisfying(new ObjectTypeSpecification(model.ObjectType)));
 }
Beispiel #7
0
        public IActionResult Index(AdvertFilter filter)
        {
            if (filter == null)
            {
                filter = new AdvertFilter();
            }

            var indexVM = new AdvertIndexViewModel
            {
                Adverts = _advertManager.GetAdverts(filter),
                Filter  = filter
            };

            return(View(indexVM));
        }
Beispiel #8
0
        public async Task <IActionResult> Index()
        {
            AdvertFilter filter = new AdvertFilter {
                CurrentPage = 1, Size = 6
            };
            var response = await _advertApiClient.GetAdvertsByFilterAsync(filter);

            ViewBag.Adverts = response.Data;

            var cats = await _categoryApiClient.GetCategoriesAsync();

            ViewBag.Categories  = cats.Data;
            ViewBag.Size        = 30;
            ViewBag.CurrentPage = 1;
            return(View());
        }
Beispiel #9
0
        public IEnumerable <Advert> GetAdverts(AdvertFilter model)
        {
            IQueryable <Advert> result;

            switch (model.RealtyType)
            {
            case RealtyType.Room:
                result = GetRooms(model);
                break;

            case RealtyType.Apartment:
                result = GetApartments(model);
                break;

            case RealtyType.Commercial:
                result = GetCommerials(model);
                break;

            case RealtyType.Garage:
                result = GetGarages(model);
                break;

            case RealtyType.House:
                result = GetHouses(model);
                break;

            case RealtyType.Land:
                result = GetLands(model);
                break;

            default:
                result = GetAllAdverts(model);
                break;
            }

            return(result
                   .SelectSatisfying(new SquareSpecification(
                                         model.SquareMin,
                                         model.SquareMax))
                   .SelectSatisfying(new GeoSpecification(
                                         model.FromLatitude,
                                         model.FromLongitude,
                                         model.ToLatitude,
                                         model.ToLongitude))
                   .AsEnumerable());
        }
Beispiel #10
0
        public async Task <IActionResult> Index(FilterAdvertViewModel viewFilter, int?page)
        {
            AdvertFilter filter = _mapper.Map <AdvertFilter>(viewFilter);

            filter.CurrentPage = 1;


            var response = await _advertApiClient.GetAdvertsByFilterAsync(filter);

            ViewBag.Adverts = response.Data;

            var cats = await _categoryApiClient.GetCategoriesAsync();

            ViewBag.Categories  = cats.Data;
            ViewBag.CurrentPage = 1;
            ViewBag.Size        = filter.Size;
            return(View());
        }
Beispiel #11
0
        public DataSet <Advert> GetAdverts(AdvertFilter filter)
        {
            var datasSet = new DataSet <Advert>();

            if (filter == null)
            {
                return(GetAdverts(true));
            }
            else
            {
                var qryBase = _context.Adverts;
                var qry     = qryBase.Select(x => x);

                if (_user != null)
                {
                    //Enkel Adverts ophalen die van ons zijn als we owner rol hebben
                    if (_userManager.IsInRoleAsync(_user, UserRoleType.RestaurantOwner.ToString()).Result)
                    {
                        List <int> ownedBusinesses = _businessManager.GetBusinesses().Data.Select(business => business.ID).ToList();
                        qry = from t in qry
                              where ownedBusinesses.Contains(t.BusinessID)
                              select t;
                    }
                }

                if (filter.BusinessID.HasValue)
                {
                    qry = from t in qry
                          where t.BusinessID == filter.BusinessID.Value
                          select t;
                }

                qry = from t in qry.Include("Business")
                      orderby t.CreatedOn descending
                      select t;
                datasSet.Data = qry.ToList();

                return(datasSet);
            }
        }
        public async Task TestAdvertFiltersAsync()
        {
            // arrange
            var advertFilter = new AdvertFilter {
                Header          = "Felix2",
                Size            = 2,
                CurrentPage     = 1,
                CreatedDateTime = null,
                Description     = null,
                CategoryId      = null,
                HasPhotoOnly    = null,
                Price           = null
            };

            // act

            var result = await _advertManager.GetAdvertsByFilterAsync(advertFilter);

            // assert

            Assert.AreEqual(1, result.Count);
        }
Beispiel #13
0
 private IQueryable <Advert> GetLands(AdvertFilter model)
 {
     return(GetAllAdverts(model)
            .OfType <Land>());
 }
        //[Route("markers")]
        public ActionResult Markers(AdvertFilter model)
        {
            var markers = AdvertService.GetAdverts(model);

            return(new JsonNetResult(markers));
        }
Beispiel #15
0
 public Task <ApiResponse <IReadOnlyCollection <AdvertDto> > > GetAdvertsByFilterAsync(AdvertFilter filter)
 {
     if (filter == null)
     {
         throw new ArgumentNullException(nameof(filter));
     }
     return(PostAsync <AdvertFilter, ApiResponse <IReadOnlyCollection <AdvertDto> > >(_advertOptions.GetAdvertsByFilterUrl, filter));
 }
Beispiel #16
0
        public async Task <IReadOnlyCollection <AdvertDto> > GetAdvertsByFilterAsync(AdvertFilter filter)
        {
            var adverts = await _advertRepository.GetAllAsync();

            if (filter == null)
            {
                throw new NullReferenceException("Не задан фильтр");
            }



            if (filter.HasPhotoOnly != null && filter.HasPhotoOnly == true)
            {
                adverts = adverts.Where(x => x.Photos.Count > 0);
            }

            if (!string.IsNullOrEmpty(filter.Header))
            {
                adverts = adverts.Where(x => EF.Functions.Like(x.Header, $"%{filter.Header}%"));
            }

            if (filter.CategoryId != null)
            {
                adverts = adverts.Where(x => x.CategoryId == filter.CategoryId || x.Category.ParentCategory.Id == filter.CategoryId);
            }

            if (filter.Region != null)
            {
                adverts = adverts.Where(x => EF.Functions.Like(x.Location.Country, $"%{filter.Region}%") || EF.Functions.Like(x.Location.Area, $"%{filter.Region}%") ||
                                        EF.Functions.Like(x.Location.City, $"%{filter.Region}%") || EF.Functions.Like(x.Location.Street, $"%{filter.Region}%"));
            }

            if (!string.IsNullOrEmpty(filter.Description))
            {
                adverts = adverts.Where(x => EF.Functions.Like(x.Description, $"%{filter.Description}%"));
            }

            if (filter.CreatedDateTime != null && filter.CreatedDateTime.From != null)
            {
                adverts = adverts.Where(x => x.CreatedDateTime > filter.CreatedDateTime.From);
            }

            if (filter.CreatedDateTime != null && filter.CreatedDateTime.To != null)
            {
                adverts = adverts.Where(x => x.CreatedDateTime < filter.CreatedDateTime.To);
            }


            if (filter.Price != null && filter.Price.From != null)
            {
                adverts = adverts.Where(x => x.Price > filter.Price.From);
            }

            if (filter.Price != null && filter.Price.To != null)
            {
                adverts = adverts.Where(x => x.Price < filter.Price.To);
            }

            if (filter.UserId != null)
            {
                adverts = adverts.Where(x => x.UserId.Equals(filter.UserId));
            }


            if (filter.AdvertId != null)
            {
                adverts = adverts.Where(x => x.Id == filter.AdvertId);
            }
            else
            {
                adverts = adverts.Select(x => new Advert
                {
                    Photos = (x.Photos.Any()) ? new List <Photo> {
                        x.Photos.FirstOrDefault()
                    } : null,
                    Id              = x.Id,
                    Header          = x.Header,
                    CreatedDateTime = x.CreatedDateTime,
                    Category        = x.Category,
                    Price           = x.Price
                });
            }



            adverts = adverts.Skip((filter.CurrentPage - 1) * filter.Size).Take(filter.Size);

            return(_mapper.Map <List <AdvertDto> >(adverts.ToArray()));
        }
Beispiel #17
0
        public async Task <IActionResult> Filter(
            [FromQuery] string Header                = default,
            [FromQuery] string Description           = default,
            [FromQuery] int CategoryId               = default,
            [FromQuery] string HasPhotoOnly          = "false",
            [FromQuery] uint?PriceFrom               = null,
            [FromQuery] uint?PriceTo                 = null,
            [FromQuery] string UserId                = default,
            [FromQuery] long?AdvertId                = null,
            [FromQuery] DateTime?CreatedDateTimeFrom = null,
            [FromQuery] DateTime?CreatedDateTimeTo   = null,
            [FromQuery] string Region                = default,
            [FromQuery] int Size         = 6,
            [FromQuery] string in_header = "true",
            [FromQuery] int page         = 1
            )
        {
            ViewData["Header"]              = Header;
            ViewData["Description"]         = Description;
            ViewData["CategoryId"]          = CategoryId;
            ViewData["HasPhotoOnly"]        = HasPhotoOnly;
            ViewData["PriceFrom"]           = PriceFrom;
            ViewData["PriceTo"]             = PriceTo;
            ViewData["UserId"]              = UserId;
            ViewData["AdvertId"]            = AdvertId;
            ViewData["CreatedDateTimeFrom"] = CreatedDateTimeFrom;
            ViewData["CreatedDateTimeTo"]   = CreatedDateTimeTo;
            ViewData["Region"]              = Region;
            ViewData["Size"]      = Size;
            ViewData["in_header"] = in_header;
            ViewData["page"]      = page;

            var cats = await _categoryApiClient.GetCategoriesAsync();

            IReadOnlyCollection <CategoryDto> cat_data = cats.Data;

            ViewBag.Categories = cat_data;
            var _filter = new FilterAdvertViewModel
            {
                Header              = Header,
                Description         = Description,
                CategoryId          = (CategoryId == 0) ? (long?)null : CategoryId,
                HasPhotoOnly        = bool.Parse(HasPhotoOnly),
                PriceFrom           = PriceFrom,
                PriceTo             = PriceTo,
                UserId              = UserId,
                AdvertId            = AdvertId,
                CreatedDateTimeFrom = CreatedDateTimeFrom,
                CreatedDateTimeTo   = CreatedDateTimeTo,
                Region              = Region,
                Size = Size
            };

            if (in_header.Equals("false"))
            {
                _filter.Description = Header;
            }

            var          viewFilter = _filter;
            int          p          = page;
            AdvertFilter filter     = _mapper.Map <AdvertFilter>(viewFilter);

            filter.CurrentPage = p;

            if (viewFilter.CreatedDateTimeTo.HasValue || viewFilter.CreatedDateTimeFrom.HasValue)
            {
                var range = new Range <DateTime>();

                if (viewFilter.CreatedDateTimeFrom.HasValue)
                {
                    range.From = viewFilter.CreatedDateTimeFrom.Value;
                }
                else
                {
                    range.From = DateTime.MinValue;
                }

                if (viewFilter.CreatedDateTimeTo.HasValue)
                {
                    range.To = viewFilter.CreatedDateTimeTo.Value;
                }
                else
                {
                    range.To = DateTime.MaxValue;
                }
                filter.CreatedDateTime = range;
            }

            if (viewFilter.PriceTo.HasValue || viewFilter.PriceFrom.HasValue)
            {
                var range = new Range <uint>();

                if (viewFilter.PriceFrom.HasValue)
                {
                    range.From = viewFilter.PriceFrom.Value;
                }
                else
                {
                    range.From = UInt32.MinValue;
                }

                if (viewFilter.PriceTo.HasValue)
                {
                    range.To = viewFilter.PriceTo.Value;
                }
                else
                {
                    range.To = UInt32.MaxValue;
                }
                filter.Price = range;
            }

            var response = await _advertApiClient.GetAdvertsByFilterAsync(filter);

            IReadOnlyCollection <AdvertDto> _ads = response.Data;

            ViewBag.Adverts     = _ads;
            ViewBag.CurrentPage = p;
            ViewBag.Size        = filter.Size;

            if (response.HasErrors)
            {
                return(View("Error", new ErrorViewModel {
                    RequestId = response.Errors.FirstOrDefault()
                }));
            }
            return(View(_filter));
        }
Beispiel #18
0
 private IQueryable <Advert> GetHouses(AdvertFilter model)
 {
     return(GetAllAdverts(model)
            .OfType <House>()
            .SelectSatisfying(new ObjectTypeSpecification(model.ObjectType)));
 }