Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }