public Task Handle(object command)
 {
     return(command switch
     {
         Create cmd => HandleCreate(cmd),
         Update cmd => HandleFullUpdate(cmd),
         SetName cmd => HandleUpdate(cmd.Id, (a) => a.SetName(cmd.Name),
                                     (a) => Repository.Update(a)),
         SetLogoPath cmd => HandleUpdate(cmd.Id, (a) => a.SetLogoPath(cmd.LogoPath),
                                         (a) => Repository.Update(a)),
         SetDescription cmd => HandleUpdate(cmd.Id, (a) => a.SetDescription(cmd.Description),
                                            (a) => Repository.Update(a)),
         DeletePublisher cmd => HandleUpdate(cmd.Id, _ => Repository.RemoveAsync(cmd.Id)),
         _ => Task.CompletedTask
     });
Example #2
0
        public Task Handle(object command)
        {
            return(command switch
            {
                Create cmd => HandleCreate(cmd),
                Update cmd => HandleFullUpdate(cmd),
                SetTitle cmd => HandleUpdate(cmd.Id, (a) => a.SetTitle(cmd.Title),
                                             (a) => Repository.Update(a)),
                SetReleaseYear cmd => HandleUpdate(cmd.Id, (a) => a.SetReleaseYear(cmd.ReleaseYear),
                                                   (a) => Repository.Update(a)),
                SetPageCount cmd => HandleUpdate(cmd.Id, (a) => a.SetPageCount(cmd.PageCount),
                                                 (a) => Repository.Update(a)),
                SetWordCount cmd => HandleUpdate(cmd.Id, (a) => a.SetWordCount(cmd.WordCount),
                                                 (a) => Repository.Update(a)),
                SetIsbn cmd => HandleUpdate(cmd.Id, (a) => a.SetIsbn(cmd.Isbn),
                                            (a) => Repository.Update(a)),
                SetBookCoverPath cmd => HandleUpdate(cmd.Id, (a) => a.SetBookCoverPath(cmd.BookCoverPath),
                                                     (a) => Repository.Update(a)),
                SetDescription cmd => HandleUpdate(cmd.Id, (a) => a.SetDescription(cmd.Description),
                                                   (a) => Repository.Update(a)),
                SetNotes cmd => HandleUpdate(cmd.Id, (a) => a.SetNotesOld(cmd.Notes),
                                             (a) => Repository.Update(a)),
                SetIsRead cmd => HandleUpdate(cmd.Id, (a) => a.SetIsRead(cmd.IsRead),
                                              (a) => Repository.Update(a)),

                SetLanguage cmd => HandleUpdateAsync(cmd.Id,
                                                     async a => await UpdateLanguageAsync(a, cmd.Language.Id)),
                SetPublisher cmd => HandleUpdateAsync(cmd.Id,
                                                      async a => await UpdatePublisherAsync(a, cmd.Publisher.Id)),

                SetAuthors cmd => HandleUpdateAsync(cmd.Id,
                                                    async a => await UpdateBookAuthorsAsync(a, cmd.Authors)),
                SetFormats cmd => HandleUpdateAsync(cmd.Id,
                                                    async a => await UpdateBookFormatsAsync(a, cmd.Formats)),
                SetGenres cmd => HandleUpdateAsync(cmd.Id,
                                                   async a => await UpdateBookGenresAsync(a, cmd.Genres)),
                SetBookReadDates cmd => HandleUpdateAsync(cmd.Id,
                                                          async a => await UpdateBookReadDatesAsync(a, cmd.BookReadDates)),
                Delete cmd => HandleDeleteAsync(cmd),
                _ => Task.CompletedTask
            });
        public void SwitchPage(int value = 0, bool relative = true, bool resetObjects = true)
        {
            if (relative)
            {
                CurrentPageIndex += value;
            }
            else
            {
                CurrentPageIndex = value;
            }

            CurrentPageIndex = CurrentPageIndex <0 ? PageCount - 1 : CurrentPageIndex> PageCount - 1 ? 0 : CurrentPageIndex;

            if (resetObjects)
            {
                void destroyObject(GameObject obj)
                {
                    obj.transform.parent = null;
                    obj.DeactivateAndDestroy();
                    DestroyImmediate(obj);
                }

                foreach (var item in MenuController.items_)
                {
                    if (SuperDuperMenu.defaultFloatValues_.ContainsKey(item.name))
                    {
                        SuperDuperMenu.defaultFloatValues_.Remove(item.name);
                    }

                    UIWidget widget = item.GetComponent <UIWidget>();

                    if (widget && MenuFade.widgets_.Contains(widget))
                    {
                        MenuFade.widgets_.Remove(widget);
                    }

                    item.gameObject.DeactivateAndDestroy();
                }

                MenuController.items_.Clear();

                MenuController.actions_.Values.Do(x => destroyObject(x.gameObject));
                MenuController.toggles_.Values.Do(x => destroyObject(x.gameObject));
                MenuController.sliders_.Values.Do(x => destroyObject(x.gameObject));
                MenuController.popups_.Values.Do(x => destroyObject(x.gameObject));

                MenuController.actions_.Clear();
                MenuController.toggles_.Clear();
                MenuController.sliders_.Clear();
                MenuController.popups_.Clear();

                MenuController.buttonsTable_.Reposition();

                MenuController.SetDescription(null, "");

                SetDescription.Broadcast(new SetDescription.Data(string.Empty, true, string.Empty));

                MenuController.Init(this);
                MenuController.Initialize();
            }
        }