Пример #1
0
        /// <summary>
        /// Takes a DB Location and maps it to a store Location. Will add
        /// to the model if not already there.
        /// </summary>
        /// <param name="DbLocation">The DB representation of the location.</param>
        /// <returns>The Model representation of the location.</returns>
        public static Store.Location MapLocationToStore(DataModel.Location DbLocation)
        {
            Store.Location StoreLocation;
            string         lname = DbLocation.LocationName;

            // if not, add to model
            if (!Locations.Instance.HasLocation(lname))
            {
                StoreLocation = Locations.Instance.RegisterLocation(lname);

                //get invintory
                foreach (Invintory inv in DbLocation.Invintories)
                {
                    try
                    {
                        StoreLocation.AddInventory(inv.ItemName, inv.Quantity);
                    } catch (ItemNotFoundException e)
                    {
                        Console.WriteLine(e.Message);
                        StoreCatalogue.Instance.RegisterItem(inv.ItemName, inv.ItemNameNavigation.ItemPrice);
                        StoreLocation.AddInventory(inv.ItemName, inv.Quantity);
                    }
                }
            }
            else
            {
                StoreLocation = Store.Locations.Instance.GetLocation(lname);
            }

            return(StoreLocation);
        }