public void DisplayStoreItems(StoreItem itemData)
    {
        StoreItemView itemView = GameObject
                                 .Instantiate(_listedStoreItemPrefab, _storeGrid.transform, false)
                                 .GetComponent <StoreItemView>();

        itemView.SetItemID(itemData.ID);

        itemView.Pressed += itemID =>
        {
            StoreItemPressed
            .Invoke(itemID, (int)itemData.VirtualCurrencyPrices["SC"]);
        };

        // clean up long references?
        string itemTitle = GameController
                           .Instance
                           .CommonItemsStore
                           .GetItem(itemData.ID)
                           .Title;

        string itemDescription = GameController
                                 .Instance
                                 .CommonItemsStore
                                 .GetItem(itemData.ID)
                                 .Description;

        itemView.SetItemTitle(itemTitle);
        itemView.SetItemPrice((int)itemData.VirtualCurrencyPrices["SC"]);
        itemView.SetItemDescription(itemDescription);
    }
Example #2
0
        public StoreItemControl(StoreItemView item)
        {
            InitializeComponent();
            Click                   += StoreItemControl_Click;
            BookImag.Source          = item.GetDisplayImage();
            ItemName.Text            = item.Name;
            ItemISBN.ToolTip         = item.ISBN;
            priceBlock.Text          = item.UnitPrice.ToString("C", CultureInfo.CurrentCulture);
            unitsBlock.Text          = item.UnitsInStock.ToString();
            discBlock.Text           = item.Discount.ToString();
            bookFields.Visibility    = Visibility.Collapsed;
            journalFields.Visibility = Visibility.Collapsed;
            nameBlock.Text           = item.Name;
            this.item                = item;

            BookView book = item as BookView;

            if (book != null)
            {
                typeBlock.Text        = "Book";
                bookFields.Visibility = Visibility.Visible;
                summBlock.Text        = book.Summary;
                authorBlock.Text      = book.Author;
                publishBlock.Text     = book.Publisher;
                dateBlock.Text        = book.PublishedDate.ToString("dd/MM/yyyy");
                if (book.CatalogNumber > 0)
                {
                    cataBlock.Text = book.CatalogNumber.ToString();
                }
                editionBlock.Text = book.Edition;
                StringBuilder st = new StringBuilder();
                for (int i = 0; i < book.Genres.Length; i++)
                {
                    if (book.Genres[i].Active)
                    {
                        st.Append($"{book.Genres[i].GenreToString}\n");
                    }
                }

                genresBlock.Text = st.ToString();
                return;
            }

            JournalView journal = item as JournalView;

            if (journal != null)
            {
                typeBlock.Text           = "Journal";
                journalFields.Visibility = Visibility.Visible;

                volumBlock.Text = journal.VolumeNumber.ToString();
                issueBlock.Text = journal.IssueNumber.ToString();
                fielBlock.Text  = journal.Field;
            }
        }
Example #3
0
    public void addItem(StoreItemView item)
    {
        if (item == null)
        {
            return;
        }

        var newItem = Instantiate(item, transform, false);

        newItem.StoreItemClickedEvent += onItemClicked;
    }
        public void TestAddStoreItem()
        {
            TestLogin();


            StoreItemView item = ViewConverter.CreateStoreItemView(book1);

            try
            {
                Logic.Instance.AddStoreItem(item);
            }catch (PrimeryKeyAllReadyExistException e)
            {
                Logger.Exception(e, "Testing add item.");
                Assert.Fail("Created an item with an all ready taken ISBN");
            }
        }
Example #5
0
        public void AddStoreItem(StoreItemView item)
        {
            if (!IsUserLoggedIn)
            {
                throw new UserLoggedInException();
            }

            if (currentUser.WorkerRank != WorkerView.Rank.Manager)
            {
                throw new UserAccessException($"{WorkerView.Rank.Manager} Access needed for that action, your Access is {currentUser.WorkerRank}.");
            }

            try
            {
                if (item is BookView)
                {
                    storeItems.Add(ViewConverter.CreateBook((BookView)item));
                    ItemAdded?.Invoke(this, item);
                }
                else if (item is JournalView)
                {
                    storeItems.Add(ViewConverter.CreateJournal((JournalView)item));
                    ItemAdded?.Invoke(this, item);
                }
                storeItems.Save();
            }
            catch (DAL.Repositorys.PrimeryKeyAllReadyExistException e)
            {
                log.Exception(e);
                throw new util.PrimeryKeyAllReadyExistException();
            }catch (RepositorySaveFailedExceptiom e)
            {
                log.Exception(e, "Failed on tring to add a new item.");
                log.Fetal("Fetal Error, App shuting down.");
                Shutdown(1);
            }
            catch (Exception e)
            {
                log.Exception(e);
                log.Fetal("Fetal Error Closing down app...");
                Shutdown(1);
            }
        }
Example #6
0
        private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ListView)sender).SelectedItem == null)
            {
                return;
            }

            StoreItemView selectedItem = ((ViewModel.Controls.StoreItemControl)((ListView)sender).SelectedItem).ItemView;
            BookView      book         = selectedItem as BookView;

            if (book != null)
            {
                updateForm.Navigate(new BookForm(book));
                return;
            }

            JournalView journal = selectedItem as JournalView;

            if (journal != null)
            {
                updateForm.Navigate(new JournalForm(journal));
                return;
            }
        }
Example #7
0
 public void onItemClicked(StoreItemView item)
 {
     basket.addItem(item);
 }
Example #8
0
 public void onItemClicked(StoreItemView item)
 {
     item.StoreItemClickedEvent -= onItemClicked;
     Destroy(item.gameObject);
 }
Example #9
0
        public void UpdateStoreItem(StoreItemView updated, StoreItemView toUpdate)
        {
            if (!IsUserLoggedIn)
            {
                throw new UserLoggedInException();
            }

            if (currentUser.WorkerRank != WorkerView.Rank.Manager)
            {
                throw new UserAccessException($"{WorkerView.Rank.Manager} Access needed for that action, your Access is {currentUser.WorkerRank}.");
            }

            StoreItem storeItem = storeItems.GetById(toUpdate.Id);

            BookView updatedBook = updated as BookView;

            if (updatedBook != null)
            {
                Book upBook   = ViewConverter.CreateBook(updatedBook);
                Book bookItem = storeItem as Book;
                if (bookItem == null)
                {
                    throw new UpdatedItemNotMachingException(updated.GetType(), toUpdate.GetType());
                }

                try
                {
                    storeItems.UpdateBook(upBook, bookItem);
                }
                catch (DAL.Repositorys.PrimeryKeyAllReadyExistException)
                {
                    throw new util.PrimeryKeyAllReadyExistException();
                }
            }
            else
            {
                JournalView updatedJournal = updated as JournalView;

                if (updatedJournal != null)
                {
                    Journal upJour   = ViewConverter.CreateJournal(updatedJournal);
                    Journal jourItem = storeItem as Journal;
                    if (jourItem == null)
                    {
                        throw new UpdatedItemNotMachingException(updated.GetType(), toUpdate.GetType());
                    }

                    try
                    {
                        storeItems.UpdateJournal(upJour, jourItem);
                    }
                    catch (DAL.Repositorys.PrimeryKeyAllReadyExistException)
                    {
                        throw new util.PrimeryKeyAllReadyExistException();
                    }
                }
            }
            try
            {
                storeItems.Save();
            }catch (RepositorySaveFailedExceptiom e)
            {
                log.Exception(e, "Failed on tring to update item.");
                log.Fetal("Fetal Error, App shuting down.");
                Shutdown(1);
            }
            ItemUpdated?.Invoke(this, updated);
        }