コード例 #1
0
        /// <summary>
        /// Attempts to edit the game, returns errors if there are any.
        /// </summary>
        /// <returns>Returns Constants.AddGameErrors enum, depicting what error occured, if any.</returns>
        public Constants.AddGameErrors EditGame()
        {
            // Checks if any of the variables are either null or empty, and returns with an error if they are.
            if (Name.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.NameInvalid);
            }
            else if (Categories.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.CategoriesInvalid);
            }
            else if (Price.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.PriceInvalid);
            }
            else if (Description.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.DescriptionInvalid);
            }

            // Parses the price string to a float.
            float _price = float.Parse(Price, System.Globalization.CultureInfo.InvariantCulture);

            // Creates a list of categories, and splits the Categories string into it.
            List <String> _categories = new List <string>();

            _categories = Categories.Split(",").ToList();
            List <CarrouselItem> _carrouselItems = new List <CarrouselItem>();

            // Creates and adds CarrouselItems to the list above, depending on what type of CarrouselItem it is.
            foreach (StorageFile file in CarrouselImages)
            {
                _carrouselItems.Add(new CarrouselItem(Constants.CarrouselItemType.Image, file.Path));
            }
            foreach (StorageFile file in CarrouselVideos)
            {
                _carrouselItems.Add(new CarrouselItem(Constants.CarrouselItemType.Video, file.Path));
            }
            foreach (ListviewString item in CarrouselYoutubeVids)
            {
                _carrouselItems.Add(new CarrouselItem(Constants.CarrouselItemType.YoutubeVideo, item.Value));
            }

            // Checks the price, and returns an error depending on whether or not it is valid.
            if (_price.ToString().Length == 0 || _price < 1 || _price > 1000)
            {
                return(Constants.AddGameErrors.PriceInvalid);
            }

            // Creates a new game with all the information.
            Game newGame = new Game(AccountHandler.Account, ThumbnailImagePath, Name, _price, 0, Description, "", _categories, _carrouselItems, _releaseDate);

            // Edits the game, and sets the SelectedGame to be the newly edited game.
            _gameList.EditGame(_gameList.SelectedGame, newGame);
            _gameList.SelectedGame = newGame;

            // Calls OnGameEdited function in GameTemplateVM.
            _gameList.GameTemplateVm.OnGameEdited();

            // Returns with no errors.
            return(Constants.AddGameErrors.NoError);
        }