public IRestaurant[] GetRestaurantsByCity(string cityName)
 {
     IRestaurant[] restaurants = new IRestaurant[0];
     try
     {
         using (var ctx = new RestaurantReviewContext())
         {
             if (string.IsNullOrWhiteSpace(cityName))
             {
                 restaurants = ctx.Restaurants.ToArray();
             }
             else
             {
                 var restaurantList = ctx.Restaurants.Where(res => cityName.Equals(res.City, StringComparison.OrdinalIgnoreCase));
                 if (restaurantList != null)
                 {
                     restaurants = restaurantList.ToArray();
                 }
             }
         }
     }
     catch (Exception e)
     {
     }
     return(restaurants);
 }
        public static string GetOrderPackageJson(IOrder order)
        {
            IRestaurant restaurant = null;

            try
            {
                restaurant = PluginContext.Operations.GetHostRestaurant();
            }
            catch (Exception e)
            {
                PluginContext.Log.Error($"get restaurant error", e);
                throw;
            }
            string json = null;

            try
            {
                var orderDto = OrderHelper.GetOrder(order);
                var package  = new OrderPackage()
                {
                    RestaurantId = restaurant.Id,
                    CompanyName  = restaurant.CompanyName,
                    Order        = orderDto
                };
                json = JsonConvert.SerializeObject(package);
            }
            catch (Exception e)
            {
                PluginContext.Log.Error($"serialize order error", e);
                throw;
            }
            return(json);
        }
        public Result AddRestaurant(IRestaurant restaurant)
        {
            Result result = new Result()
            {
                IsSuccessful = true
            };

            try
            {
                using (var ctx = new RestaurantReviewContext())
                {
                    Restaurant res = restaurant as Restaurant;
                    res.RestaurantID = Guid.NewGuid().ToString();

                    ctx.Restaurants.Add(res);
                    ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.IsSuccessful = false;
                result.Message      = e.Message;
            }

            return(result);
        }
Beispiel #4
0
 public DishesController(IDish dish, IRestaurant rest, ICategory cat, IMenu menu)
 {
     _dishRepo      = dish;
     this._restRepo = rest;
     this._catRepo  = cat;
     this._menuRepo = menu;
 }
Beispiel #5
0
        protected AbstractCook(IRestaurant restaurant) : base(restaurant)
        {
            _isFree = true;
            _locker = new object();

            OrderCompleted = delegate { };
        }
 public OrdersController(IOrder orderRepo, IShoppingCart shoppingCart, UserManager <ApplicationUser> userManager, IRestaurant restaurant /*, IAddress address*/)
 {
     this.orderRepo    = orderRepo;
     this.shoppingCart = shoppingCart;
     this.userManager  = userManager;
     this.restaurant   = restaurant;
 }
Beispiel #7
0
        public static Restaurant MapFromEntity(IRestaurant restaurant)
        {
            if (restaurant == null)
            {
                return(null);
            }

            return(new Restaurant()
            {
                Id = restaurant.id,
                Name = restaurant.Name,
                Phone = restaurant.Phone,
                Website = restaurant.Website,
                Email = restaurant.Email,
                Hours = restaurant.Hours != null?restaurant.Hours.Select(h => new Hours()
                {
                    DayOfWeek = h.DayOfWeek, OpeningTime = h.OpeningTime, ClosingTime = h.ClosingTime
                }).ToList() : null,
                            TimeZone = restaurant.TimeZone,
                            AddressLine1 = restaurant.AddressLine1,
                            AddressLine2 = restaurant.AddressLine2,
                            City = restaurant.City,
                            State = restaurant.State,
                            ZipCode = restaurant.ZipCode,
                            AwesomenessLevel = restaurant.AwesomenessLevel,
                            CreatedByUserId = restaurant.CreatedByUserId,
                            ModifiedByUserId = restaurant.ModifiedByUserId
            });
        }
Beispiel #8
0
 public RestaurantsController(IRestaurant context, IDish dish, ICategory cat, IMenu menu)
 {
     this._restRepo = context;
     this._dishRepo = dish;
     this._catRepo  = cat;
     this._menuRepo = menu;
 }
Beispiel #9
0
        public AbstractProductDeliveryWindow(IRestaurant restaurant, int windowNumber) : base(restaurant)
        {
            WindowNumber = windowNumber;

            _completedOrders = new Dictionary <int, AbstractCompletedOrder>();

            CompletedOrderTaken = delegate { };
        }
Beispiel #10
0
 private void AssertRestaurantEquals(IRestaurant rx, RestaurantViewJsonModel ry)
 {
     Assert.AreEqual(rx.Id, ry.Id);
     Assert.AreEqual(rx.LogoUrl, ry.LogoUrl);
     Assert.AreEqual(rx.Name, ry.Name);
     Assert.AreEqual(rx.Rating, ry.Rating);
     Assert.IsTrue((rx.CusineTypes == null && ry.CusineTypes == null) || rx.CusineTypes.SequenceEqual(ry.CusineTypes));
 }
        public RestaurantActionsLogger(IRestaurant restaurant)
        {
            _restaurant = restaurant ?? throw new ArgumentNullException(nameof(IRestaurant), "Argument is null.");

            Logged = delegate { };

            Subscribe();
        }
        public void SaveRestaurant(IRestaurant restaurant)
        {
            if (restaurant == null)
            {
                throw new ArgumentNullException(nameof(restaurant));
            }

            _restaurantRepository.Save(restaurant);
        }
Beispiel #13
0
        protected AbstractTable(IRestaurant restaurant) : base(restaurant)
        {
            _completingOrdersNumbers      = new LinkedList <int>();
            _completedOrdersInfosByNumber = new Dictionary <int, int>();

            _locker = new object();

            OrderMarkedCompleted = delegate { };
        }
        public void Create(IRestaurant restaurant)
        {
            if (restaurant == null)
            {
                throw new ArgumentNullException("restaurant");
            }

            _restaurantRepository.Create(restaurant);
        }
Beispiel #15
0
 private RestaurantEditModel GetRestaurantEditModel(IRestaurant restaurant)
 {
     return(new RestaurantEditModel()
     {
         Name = restaurant.Name,
         CuisineType = restaurant.Cuisine,
         Address = restaurant.Address
     });
 }
Beispiel #16
0
 private RestaurantViewModel GetRestaurantViewModel(IRestaurant restaurant)
 {
     return(new RestaurantViewModel()
     {
         Id = restaurant.Id,
         Name = restaurant.Name,
         CuisineType = restaurant.Cuisine,
         Address = restaurant.Address
     });
 }
Beispiel #17
0
        public int CreateRestaurant(IRestaurant restaurant)
        {
            var entity = _mapper.Map <RestaurantEntity>(restaurant);

            _dbContext
            .Restaurants
            .Add(entity);
            _dbContext.SaveChanges();

            return(entity.Id);
        }
Beispiel #18
0
        /// <summary>
        ///     Adds a new restaurant
        /// </summary>
        /// <param name="restaurant"></param>
        public void AddRestaurant(IRestaurant restaurant)
        {
            if (_restaurants.Contains(restaurant))
            {
                throw new Exception("Restaurant is already added");
            }

            _restaurants.Add(restaurant);

            _log.Info("Restaurant added: " + restaurant.GetCommand() + " (" + restaurant.GetName() + ")");
        }
Beispiel #19
0
        public void UpdateRestaurant(IRestaurant restaurant)
        {
            if (restaurant == null)
            {
                throw new ArgumentNullException(nameof(restaurant));
            }

            var existingRestaurant = GetRestaurant(restaurant.id);

            UpdateRestaurantFields(existingRestaurant, restaurant);

            _restaurantDataAccess.SaveRestaurant(existingRestaurant);
        }
Beispiel #20
0
        public bool EditRestaurant(int id, Restaurant res)
        {
            IRestaurant restaurant = this.GetRestaurant(id);

            if (restaurant != null)
            {
                restaurant.Name    = res.Name;
                restaurant.Cuisine = res.Cuisine;
                restaurant.Address = res.Address;
                return(true);
            }
            return(false);
        }
Beispiel #21
0
        /// <summary>
        ///     Returns the current menu of the given restaurant.
        /// </summary>
        /// <param name="restaurantCommand"></param>
        /// <returns></returns>
        public string GetMenu(string restaurantCommand)
        {
            IRestaurant restaurant = _restaurants.Find(x => x.GetCommand().Equals(restaurantCommand));

            if (restaurant == null)
            {
                throw new Exception("Unknown restaurant: " + restaurantCommand.Substring(0, 100));
            }

            StatisticsCollector.GetInstance().IncrementExecutedRestaurantMenuRequestCount();

            _log.Info("Getting menu of restaurant: " + restaurant.GetName());

            return(restaurant.GetCurrentMenu());
        }
Beispiel #22
0
        public Guid CreateRestaurant(IRestaurant restaurant)
        {
            if (restaurant == null)
            {
                throw new ArgumentNullException(nameof(restaurant));
            }

            restaurant.id         = Guid.NewGuid();
            restaurant.CreatedOn  = DateTime.UtcNow;
            restaurant.ModifiedOn = DateTime.UtcNow;

            _restaurantDataAccess.SaveRestaurant(restaurant);

            return(restaurant.id);
        }
Beispiel #23
0
        public void UpdateRestaurant(int id, IRestaurant restaurant)
        {
            RestaurantEntity entity = _dbContext
                                      .Restaurants
                                      .Include(e => e.Address)
                                      .FirstOrDefault(r => r.Id == id);

            if (entity is null)
            {
                throw new NotFoundException("Restaurant not found.");
            }

            entity = _mapper.Map(restaurant, entity);
            _dbContext.Restaurants.Update(entity);
            _dbContext.SaveChanges();
        }
Beispiel #24
0
 private static void UpdateRestaurantFields(IRestaurant existingRestaurant, IRestaurant restaurant)
 {
     existingRestaurant.AddressLine1     = restaurant.AddressLine1;
     existingRestaurant.AddressLine2     = restaurant.AddressLine2;
     existingRestaurant.City             = restaurant.City;
     existingRestaurant.Email            = restaurant.Email;
     existingRestaurant.Hours            = restaurant.Hours;
     existingRestaurant.ModifiedByUserId = restaurant.ModifiedByUserId;
     existingRestaurant.ModifiedOn       = DateTime.UtcNow;
     existingRestaurant.Name             = restaurant.Name;
     existingRestaurant.Phone            = restaurant.Phone;
     existingRestaurant.State            = restaurant.State;
     existingRestaurant.TimeZone         = restaurant.TimeZone;
     existingRestaurant.Website          = restaurant.Website;
     existingRestaurant.ZipCode          = restaurant.ZipCode;
 }
    public static void Go()
    {
        MarioPizzeria mp = new MarioPizzeria();

        // This line calls MarioPizzeria’s public GetMenu method
        mp.GetMenu();

        // These lines call MarioPizzeria’s IWindow.GetMenu method
        IWindow window = mp;

        window.GetMenu();

        // These lines call MarioPizzeria’s IRestaurant.GetMenu method
        IRestaurant restaurant = mp;

        restaurant.GetMenu();
    }
Beispiel #26
0
        public void AddRestaurantTest()
        {
            IRestaurant existingRestaurant = _container.Resolve <IRestaurant>();

            existingRestaurant.Name = "Test Restaurant 1";
            Result result = _dataAccessLayer.AddRestaurant(existingRestaurant);

            Assert.IsFalse(result.IsSuccessful);
            Assert.IsNotNull(result.Message);

            IRestaurant newRestaurant = _container.Resolve <IRestaurant>();

            newRestaurant.Name = "Test Restaurant 3";
            newRestaurant.City = "Harrisburg";
            result             = _dataAccessLayer.AddRestaurant(newRestaurant);
            Assert.IsTrue(result.IsSuccessful);
            Assert.IsNull(result.Message);
        }
Beispiel #27
0
        public IActionResult RestaurantCreate(RestaurantEditModel restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(RestaurantCreate)));
            }

            var res = new Restaurant()
            {
                Address = restaurant.Address,
                Cuisine = restaurant.CuisineType,
                Name    = restaurant.Name
            };

            IRestaurant result = _restaurantManager.AddRestaurant(res);

            return(RedirectToAction("Details", new { id = result.Id }));
        }
        private void SetupMocks()
        {
            // 1. Create moq object
            var restarantInfoMoq = new Mock <IRestaurant>();


            //2. Setup the returnables

            var moqRestaurant = new MockRestaurantService();


            // 3. Assign to Object when needed
            var handler = new Mock <HttpMessageHandler>();

            factory = handler.CreateClientFactory();


            cache      = new InMemoryCacheService(new MemoryCache(new MemoryCacheOptions()));
            logger     = new Mock <ILogger <RestaurantInfoService> >().Object;
            restaurant = moqRestaurant;
        }
Beispiel #29
0
        private static void testGenericInterface()
        {
            Int32 x = 1, y = 2;
            IComparable <Int32> c      = x;

            // CompareTo ожидает Object,
            // но вполне допустимо передать переменную y типа Int32
            c.CompareTo(y); // Выполняется упаковка
            // CompareTo ожидает Int32,
            // передача "2" (тип String) приводит к ошибке компиляции
            // с сообщением о невозможности привести тип String к Int32
            // c.CompareTo("2"); // Ошибка

            Number n = new Number();
            // Значение n сравнивается со значением 5 типа Int32
            IComparable <Int32> cInt32 = n;
            Int32 result = cInt32.CompareTo(5);
            // Значение n сравнивается со значением "5" типа String
            IComparable <String> cString = n;

            result = cString.CompareTo("5");

            MarioPizzeria mp = new MarioPizzeria();

            // Эта строка вызывает открытый метод GetMenu класса MarioPizzeria
            mp.GetMenu();
            // Эти строки вызывают метод IWindow.GetMenu
            IWindow window = mp;

            window.GetMenu();
            // Эти строки вызывают метод IRestaurant.GetMenu
            IRestaurant restaurant = mp;

            restaurant.GetMenu();

            SomeValueType v  = new SomeValueType(0);
            Object        o  = new Object();
            Int32         n1 = v.CompareTo(v); // Без упаковки
            // n1 = v.CompareTo(o); // Ошибка компиляции
        }
        public Result AddRestaurant(IRestaurant restaurant)
        {
            Result result = new Result()
            {
                IsSuccessful = true
            };
            string            filePath    = ConfigurationManager.AppSettings["RestaurantsXMLFilePath"];
            List <Restaurant> restaurants = new List <Restaurant>();

            //Get a list of existing restaurants from disk
            try
            {
                restaurants = deserializeFromDisk <List <Restaurant> >(filePath);
            }
            catch (Exception e)
            {
                result.IsSuccessful = false;
                result.Message      = e.Message;
            }

            //Check if the restaurant already exists and if so return
            //an error message.
            if (doesRestaurantExist((Restaurant)restaurant, restaurants))
            {
                result.IsSuccessful = false;
                result.Message      = Constants.ErrorMessageRestaurantExists;
                return(result);
            }

            //Generate new ID and add the restaurant to the list of
            //restaurants
            restaurant.RestaurantID = Guid.NewGuid().ToString();
            restaurants.Add((Restaurant)restaurant);

            //Save the list to disk
            result = serializeToDisk(restaurants, filePath);

            return(result);
        }
Beispiel #31
0
 public bool Equals(IRestaurant other)
 {
     return other.GetCommand() == GetCommand();
 }