Пример #1
0
        public static void UpdateIndicesAfterShopUpdate()
        {
            foreach (var inmate in Inmates)
            {
                var shop = Shops.SingleOrDefault(s => s.Id == inmate.ShopId);
                if (shop == null)
                {
                    inmate.ShopIndex = -1;
                }
                else
                {
                    inmate.ShopIndex = Shops.IndexOf(shop);
                }
            }

            foreach (var tool in Tools)
            {
                var shop = Shops.SingleOrDefault(s => s.Id == tool.ShopId);
                if (shop == null)
                {
                    tool.ShopIndex = -1;
                }
                else
                {
                    tool.ShopIndex = Shops.IndexOf(shop);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Maps domain to view model and adds to observable collection.
        /// </summary>
        /// <param name="tool"></param>
        public static void MapToolToViewModel(Tool tool)
        {
            // shop obj needed to get the shop index for the drop down menu
            var shop = Shops.SingleOrDefault(s => s.Id == tool.ShopId);

            Tools.Add(new ToolViewModel
            {
                Id          = tool.Id,
                ToolNumber  = tool.ToolNumber,
                Description = tool.Description,
                ShopId      = shop?.Id,
                ShopIndex   = Shops.IndexOf(shop)
            });
        }
Пример #3
0
        public static void MapInmateToViewModel(Inmate inmate)
        {
            // shop obj needed to get the shop index for the drop down menu
            var shop = Shops.SingleOrDefault(s => s.Id == inmate.ShopId);

            Inmates.Add(new InmateViewModel
            {
                Id        = inmate.Id,
                FirstName = inmate.FirstName,
                LastName  = inmate.LastName,
                GDCNumber = inmate.GDCNumber,
                ShopId    = inmate.ShopId,
                ShopIndex = Shops.IndexOf(shop)
            });
        }
        public ShopController(string shopName) // Определяет текущий магазин. Если такого нет, то создает новый.
        {
            Shops = GetShopsData();

            CurrentShop = Shops.SingleOrDefault(s => s.Name == shopName);

            if (CurrentShop == null)
            {
                CurrentShop = new Shop(shopName);
                Shops.Add(CurrentShop);
                IsNewShop = true;
                SaveShops();
            }

            else
            {
                CurrentShop.Products = GetAllProducts();
            }
        }
 public void AddNewShop(string name) // Добавляю новый магазин. Либо, если такой уже есть, то делаю его текущим.
 {
     if (String.IsNullOrWhiteSpace(name))
     {
         Console.WriteLine("Название магазина не заполнено. Вернитесь в меню и повторите попытку.\n");
     }
     else
     {
         CurrentShop = Shops.SingleOrDefault(s => s.Name == name);
         if (CurrentShop == null)
         {
             CurrentShop = new Shop(name);
             Shops.Add(CurrentShop);
             IsNewShop = true;
             SaveShops();
         }
         else
         {
             CurrentShop.Products = GetAllProducts();
         }
     }
 }