private void ExportAdventure(AdventureViewModel adventureViewModel)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter   = "Adventure Archive|*.ccea|Word Document|*.docx";
            saveFileDialog.Title    = "Save Adventure";
            saveFileDialog.FileName = adventureViewModel.Name;

            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    string ext = Path.GetExtension(saveFileDialog.FileName);

                    if (ext == ".ccaa")
                    {
                        byte[] bytes = _dataManager.CreateAdventureArchive(adventureViewModel.AdventureModel);
                        File.WriteAllBytes(saveFileDialog.FileName, bytes);
                    }
                    else if (ext == "*.docx")
                    {
                        //_documentService.CreateWordDoc(saveFileDialog.FileName, adventureViewModel);
                    }
                    else
                    {
                        _dialogService.ShowConfirmationDialog("Unable To Export", "Invalid file extension.", "OK", null, null);
                    }
                }
                catch (Exception)
                {
                    _dialogService.ShowConfirmationDialog("Unable To Export", "An error occurred when attempting to export the adventure.", "OK", null, null);
                }
            }
        }
        private void SelectPrevious()
        {
            if (_adventures.Any())
            {
                ListItemViewModel <AdventureModel> selected = _adventures.FirstOrDefault(x => x.IsSelected);

                foreach (ListItemViewModel <AdventureModel> adventure in _adventures)
                {
                    adventure.IsSelected = false;
                }

                if (selected == null)
                {
                    _adventures[_adventures.Count - 1].IsSelected = true;
                    _selectedAdventure = new AdventureViewModel(_adventures[_adventures.Count - 1].Model);
                }
                else
                {
                    int index = Math.Max(_adventures.IndexOf(selected) - 1, 0);
                    _adventures[index].IsSelected = true;
                    _selectedAdventure            = new AdventureViewModel(_adventures[index].Model);
                }

                OnPropertyChanged(nameof(SelectedAdventure));
            }
        }
        private void Delete()
        {
            if (_selectedAdventure != null)
            {
                string message = String.Format("Are you sure you want to delete {0}?",
                                               _selectedAdventure.Name);

                bool?result = _dialogService.ShowConfirmationDialog("Delete Adventure", message, "Yes", "No", null);

                if (result == true)
                {
                    _compendium.DeleteAdventure(_selectedAdventure.AdventureModel.Id);

                    ListItemViewModel <AdventureModel> listItem = _adventures.FirstOrDefault(x => x.Model.Id == _selectedAdventure.AdventureModel.Id);
                    if (listItem != null)
                    {
                        _adventures.Remove(listItem);
                    }

                    _selectedAdventure = null;

                    _compendium.SaveAdventures();

                    OnPropertyChanged(nameof(SelectedAdventure));

                    if (_adventureEditViewModel != null)
                    {
                        CancelEditAdventure();
                    }
                }
            }
        }
示例#4
0
        public ActionResult AdventureCounter(string ChId)
        {
            AdventureViewModel model = new AdventureViewModel();

            model.Character = db.Characters.Where(y => y.ApplicationUserID == User.Identity.Name).FirstOrDefault();
            model.Adventure = db.Adventures.Find(model.Character.AdventureID);

            base.SetModelProperties(model);
            return(View(model));
        }
示例#5
0
        public async Task <IActionResult> Index()
        {
            var items = await adventureService.getOngoingAdventuresAsync();

            var model = new AdventureViewModel()
            {
                adventures = items
            };

            return(View(model));
        }
        private void EditAdventure(AdventureViewModel adventureModel)
        {
            if (adventureModel != null)
            {
                _adventureEditViewModel = new AdventureEditViewModel(adventureModel.AdventureModel);
                _adventureEditViewModel.PropertyChanged += _adventureEditViewModel_PropertyChanged;

                OnPropertyChanged(nameof(EditingAdventure));
                OnPropertyChanged(nameof(IsEditingAdventure));
            }
        }
示例#7
0
        public ActionResult Index()
        {
            AdventureViewModel model = new AdventureViewModel();

            model.Character       = db.Characters.Where(y => y.ApplicationUserID == User.Identity.Name).FirstOrDefault();
            model.Adventures      = db.Adventures.ToList();
            model.AdventureDrops  = db.AdventureDrops.ToList();
            model.PossibleZombies = db.Zombies.ToList();

            base.SetModelProperties(model);
            return(View(model));
        }
示例#8
0
        public ActionResult OnAdventure(string id)
        {
            AdventureViewModel model = new AdventureViewModel();

            model.Character = db.Characters.Where(y => y.ApplicationUserID == User.Identity.Name).FirstOrDefault();


            if (model.Character.IsOnAdventure == false)
            {
                return(RedirectToAction("Index", "Adventures"));
            }

            model.Adventure = db.Adventures.Find(model.Character.AdventureID);

            model.ZombiesAttackAdventurer = db.ZombieAttackAdventurers.Where(x => x.CharacterID == model.Character.CharacterID).ToList();
            model.Weapons = db.Weapons.ToList();
            model.Adventure.AdventureSteps = db.Adventures.Find(model.Character.AdventureID).AdventureSteps;

            ViewBag.WhosTurn = new AdventuresController().WhosTurn(User.Identity.Name);

            foreach (var zombie in model.ZombiesAttackAdventurer)
            {
                zombie.Zombie = db.Zombies.Find(zombie.ZombieID);
            }

            for (int c = 1; c < model.Adventure.AdventureSteps + 1; c++)
            {
                int counter = model.ZombiesAttackAdventurer.Where(x => x.State == c).Count();
                if (model.Character.AdventureState == c && counter == 0)
                {
                    model.Character.AdventureState++;
                    model.Character.FinishAdventure      = DateTime.Now.AddSeconds(model.Adventure.AdventureWaitingTime);
                    model.Character.isWaitingOnAdventure = true;
                    db.SaveChanges();
                    return(RedirectToAction("AdventureCounter", "Adventures", new { AdId = model.Adventure.AdventureID, ChId = User.Identity.Name }));
                }
                if (counter > 0 && model.Character.AdventureState <= model.Adventure.AdventureSteps)
                {
                    model.Character.AdventureState = c;
                    break;
                }
            }

            List <ZombieAttackAdventurer> zombieAttackInThisTurn = new List <ZombieAttackAdventurer>();

            zombieAttackInThisTurn = db.ZombieAttackAdventurers.Where(x => x.CharacterID == model.Character.CharacterID).Where(x => x.State == model.Character.AdventureState).ToList();

            db.SaveChanges();

            base.SetModelProperties(model);
            return(View(model));
        }
        private void SelectAdventure(ListItemViewModel <AdventureModel> adventureItem)
        {
            bool selectAdventure = true;

            if (_adventureEditViewModel != null)
            {
                if (_editHasUnsavedChanges)
                {
                    string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                _selectedAdventure.Name, Environment.NewLine + Environment.NewLine);
                    string accept = "Save and Continue";
                    string reject = "Discard Changes";
                    string cancel = "Cancel Navigation";
                    bool?  result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel);

                    if (result == true)
                    {
                        if (!SaveEditAdventure())
                        {
                            selectAdventure = false;
                        }
                    }
                    else if (result == false)
                    {
                        CancelEditAdventure();
                    }
                    else
                    {
                        selectAdventure = false;
                    }
                }
                else
                {
                    CancelEditAdventure();
                }
            }

            if (selectAdventure)
            {
                foreach (ListItemViewModel <AdventureModel> item in _adventures)
                {
                    item.IsSelected = false;
                }
                adventureItem.IsSelected = true;

                _selectedAdventure = new AdventureViewModel(adventureItem.Model);
                OnPropertyChanged(nameof(SelectedAdventure));
            }
        }
示例#10
0
        public ActionResult StopAdventure(int AdId, int ChId, string returnUrl)
        {
            AdventureViewModel model = new AdventureViewModel();

            Character character = db.Characters.Where(y => y.CharacterID == ChId).FirstOrDefault();
            List <ZombieAttackAdventurer> zombies = db.ZombieAttackAdventurers.Where(x => x.CharacterID == ChId).ToList();
            Adventure adventure = db.Adventures.Find(AdId);

            zombies.ForEach(x => db.ZombieAttackAdventurers.Remove(x));
            character.IsOnAdventure   = false;
            character.FinishAdventure = DateTime.MaxValue;

            db.SaveChanges();

            return(RedirectToAction(returnUrl));
        }
        private bool SaveEditAdventure()
        {
            bool saved = false;

            if (_adventureEditViewModel.AdventureModel != null)
            {
                _adventureEditViewModel.AdventureModel.Id = _selectedAdventure.AdventureModel.Id;
                _compendium.UpdateAdventure(_adventureEditViewModel.AdventureModel);

                _selectedAdventure = new AdventureViewModel(_adventureEditViewModel.AdventureModel);

                ListItemViewModel <AdventureModel> oldListItem = _adventures.FirstOrDefault(x => x.Model.Id == _adventureEditViewModel.AdventureModel.Id);
                if (oldListItem != null)
                {
                    if (_adventureSearchService.SearchInputApplies(_adventureSearchInput, _adventureEditViewModel.AdventureModel))
                    {
                        InitializeListItemDetails(oldListItem, _adventureEditViewModel.AdventureModel);
                    }
                    else
                    {
                        _adventures.Remove(oldListItem);
                    }
                }

                _adventureEditViewModel = null;
                _editHasUnsavedChanges  = false;

                SortAdventures();

                _compendium.SaveAdventures();

                OnPropertyChanged(nameof(SelectedAdventure));
                OnPropertyChanged(nameof(EditingAdventure));
                OnPropertyChanged(nameof(IsEditingAdventure));
                OnPropertyChanged(nameof(HasUnsavedChanges));

                saved = true;
            }

            return(saved);
        }
        private void Copy()
        {
            if (_selectedAdventure != null)
            {
                bool copyAdventure = true;

                if (_adventureEditViewModel != null)
                {
                    if (_editHasUnsavedChanges)
                    {
                        string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                    _selectedAdventure.Name, Environment.NewLine + Environment.NewLine);
                        string accept = "Save and Continue";
                        string reject = "Discard Changes";
                        string cancel = "Cancel Navigation";
                        bool?  result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel);

                        if (result == true)
                        {
                            if (!SaveEditAdventure())
                            {
                                copyAdventure = false;
                            }
                        }
                        else if (result == false)
                        {
                            CancelEditAdventure();
                        }
                        else
                        {
                            copyAdventure = false;
                        }
                    }
                    else
                    {
                        CancelEditAdventure();
                    }
                }

                if (copyAdventure)
                {
                    AdventureModel adventureModel = new AdventureModel(_selectedAdventure.AdventureModel);
                    adventureModel.Name += " (copy)";
                    adventureModel.Id    = Guid.NewGuid();

                    _compendium.AddAdventure(adventureModel);

                    if (_adventureSearchService.SearchInputApplies(_adventureSearchInput, adventureModel))
                    {
                        ListItemViewModel <AdventureModel> listItem = new ListItemViewModel <AdventureModel>(adventureModel);
                        InitializeListItemDetails(listItem, adventureModel);
                        _adventures.Add(listItem);
                        foreach (ListItemViewModel <AdventureModel> item in _adventures)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedAdventure = new AdventureViewModel(adventureModel);

                    SortAdventures();

                    _compendium.SaveAdventures();

                    OnPropertyChanged(nameof(SelectedAdventure));
                }
            }
        }