Пример #1
0
        public ServiceResponse <RestaurantDto> Get(int id)
        {
            var result = new ServiceResponse <RestaurantDto>();

            try
            {
                var restaurant = _service.Get(id);
                if (restaurant != null)
                {
                    result.Object = new RestaurantDto()
                    {
                        IdRestaurant = restaurant.IdRestaurant,
                        Name         = restaurant.Name
                    };

                    result.Result = true;
                }
            }
            catch (Exception ex)
            {
                result.Messages.Add("Problems when try to get the restaurant: " + ex.Message);
            }

            return(result);
        }
Пример #2
0
        public ServiceResponse <List <DishDto> > List()
        {
            var result = new ServiceResponse <List <DishDto> >();

            try
            {
                var dishes = _service.List();
                if (dishes.Any())
                {
                    result.Object = new List <DishDto>();
                    dishes.ForEach(x => {
                        var restaurant = _serviceRestaurant.Get(x.IdRestaurant);

                        result.Object.Add(new DishDto()
                        {
                            Name         = x.Name,
                            IdDish       = x.IdDish,
                            Price        = x.Price,
                            IdRestaurant = x.Restaurant.IdRestaurant,
                            Restaurant   = new RestaurantDto()
                            {
                                IdRestaurant = restaurant.IdRestaurant,
                                Name         = restaurant.Name
                            }
                        });
                    });
                    result.Result = true;
                }
            }
            catch (Exception ex)
            {
                result.Messages.Add("Problems when try to list dishes: " + ex.Message);
            }

            return(result);
        }