Beispiel #1
0
        public async Task CreateNewRestaurantAsync(StoreRequestModel model)
        {
            var dtoRestaurant = new Store()
            {
                Name         = model.Name,
                Address      = model.Address,
                Municipality = (Municipality)model.Municipality,
                Collections  = new List <StoreItem>()
            };

            await _restaurantRepository.InsertRestaurantAsync(dtoRestaurant);
        }
        public async Task <IActionResult> GetStoresAsync([FromQuery] string name,
                                                         [FromQuery] string address,
                                                         [FromQuery] Municipality?municipality)
        {
            var requestModel = new StoreRequestModel()
            {
                Name         = name,
                Address      = address,
                Municipality = municipality
            };

            var response = await _storeService.GetRestaurantsAsync(requestModel);

            return(Ok(response));
        }
Beispiel #3
0
        public async Task <List <StoreRequestModel> > GetRestaurantsAsync(StoreRequestModel requestModel)
        {
            Expression <Func <Store, bool> > filter = f => true;

            if (!string.IsNullOrEmpty(requestModel.Name))
            {
                filter = filter.AndAlso(x => x.Name.ToLower().Contains(requestModel.Name.ToLower()));
            }

            if (!string.IsNullOrEmpty(requestModel.Address))
            {
                filter = filter.AndAlso(x => x.Address.ToLower().Contains(requestModel.Address.ToLower()));
            }

            if (requestModel.Municipality.HasValue)
            {
                filter = filter.AndAlso(x => x.Municipality == requestModel.Municipality);
            }

            var restaurantList = await _restaurantRepository.GetRestaurantsAsync(filter);

            var mapToRestaurantRequestModel = new List <StoreRequestModel>();

            foreach (var restaurant in restaurantList)
            {
                var tempModel = new StoreRequestModel()
                {
                    Id           = restaurant.Id,
                    Name         = restaurant.Name,
                    Address      = restaurant.Address,
                    Municipality = restaurant.Municipality,
                    Collections  = restaurant.Collections
                };

                mapToRestaurantRequestModel.Add(tempModel);
            }

            return(mapToRestaurantRequestModel);
        }
        public async Task <IActionResult> AddStoreAsync([FromBody] StoreRequestModel model)
        {
            await _storeService.CreateNewRestaurantAsync(model);

            return(Ok());
        }
Beispiel #5
0
 public IActionResult Post(StoreRequestModel storeRequestModel)
 {
     return(Ok(_storeService.Add(_mapper.Map <Stores>(storeRequestModel))));
 }