Ejemplo n.º 1
0
        public async Task <int> AddGameAsync(GameAddModel game)
        {
            throw new NotImplementedException();
            //var validator = DataValidatorHelper.Validate(game);


            //if(validator.IsValid)
            //{
            //    var gameDB = await GetGameByTitleAsync(game.Title);

            //    if (gameDB == null)
            //    {
            //        Console.WriteLine($"{game.Title} has been added to database");

            //        return await _gamedbAccess.AddGameAsync(game);
            //    }

            //    return gameDB.GameID;
            //}


            //Console.WriteLine($"Invalid Data from {nameof(GameAddModel)}");
            //validator.Errors.ForEach(e => Console.WriteLine(e));

            //throw new Exception("Some data are invalid");
        }
Ejemplo n.º 2
0
        public async Task <int> AddGameAsync(GameAddModel gameAddModel)
        {
            // need to fix
            string query = $@"INSERT INTO game (Title, Type, About, Website, Thumbnail, Description,
                   HeaderImage, Background,SteamAppId, ReleaseDateId) OUTPUT Inserted.GameId 
    VALUES(@Title, @Type,@About, @Website,@Thumbnail, @Description,
                   @HeaderImage, @Background)";

            return(await SaveDataAsync(query, gameAddModel));
        }
Ejemplo n.º 3
0
        public string AddGame(GameAddModel game)
        {
            Game newGame = new Game();

            newGame.GameName       = game.GameName;
            newGame.GameNumber     = game.GameNumber;
            newGame.OrganizationId = game.OrganizationId;

            uow.GameRepository.Create(newGame);
            return("Game is created");
        }
Ejemplo n.º 4
0
        public ActionResult Index(string button, GameAddModel model, HttpPostedFileBase image)
        {
            var connectionString   = GetDatabaseConnection(ConnectionName);
            AuthorizationData data = new AuthorizationData();

            using (var conn = new SqlConnection(connectionString))

                switch (button)
                {
                case "Add User":
                    using (var command = new SqlCommand("InsertUser", conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        command.Parameters.AddWithValue("@UserName", model.UserName);
                        command.Parameters.AddWithValue("@Email", model.UserEmail);
                        command.Parameters.AddWithValue("@Password", model.UserPassword);
                        var returnParameter = command.Parameters.Add("@ReturnVal", SqlDbType.Int);
                        returnParameter.Direction = ParameterDirection.ReturnValue;
                        conn.Open();
                        command.ExecuteNonQuery();
                        var result = Convert.ToBoolean(returnParameter.Value);
                        conn.Close();

                        if (result == false)
                        {
                            data.Status = false;
                        }
                        else
                        {
                            data.Status = true;
                        }
                    }
                    if (data.Status == true)
                    {
                        ModelState.AddModelError("", "The user with this email already exist.");
                        return(View(model));
                    }
                    break;

                case "Add Game":
                    string path = @"C:\1\IMZ\trunk\InetMagaz\InetMagaz\Content\Images\";

                    if (image != null)
                    {
                        image.SaveAs(path + image.FileName);
                    }

                    string saveToBaseUrl = "./Content/Images/";

                    using (var command = new SqlCommand("InsertGame", conn)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        command.Parameters.AddWithValue("@Name", model.GameName);
                        command.Parameters.AddWithValue("@Description", model.GameDescription);
                        command.Parameters.AddWithValue("@ImageUrl", (saveToBaseUrl + image.FileName));
                        command.Parameters.AddWithValue("@Price", Convert.ToInt32(model.GamePrice));
                        conn.Open();
                        command.ExecuteNonQuery();
                        conn.Close();
                    }
                    break;
                }
            return(View());
        }