public ActionResult InsertView(InputModel input)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            if (input.TeamOne == null && input.TeamTwo == null)
            {
               return RedirectToAction("InsertView");
            }
            var teamVsTeam = string.Format("{0} vs {1}", input.TeamOne, input.TeamTwo);
            var result = string.Format("{0} : {1}", input.TeamOneResult, input.TeamTwoResult);

            var serviceInput = new ScoreModel {Date = input.Date, Result = result, TeamVsTeam = teamVsTeam};

            const string serviceUrl = ServiceConfig.DataAccessServicePath + "InsertNewRecord";
            var success = ServiceHelper.PostToService<ScoreModel, bool>(serviceUrl, serviceInput);

            // TODO: Use the result of the POST to notify the user of the outcome of the operation
            if (success)
            {

            }
            else
            {

            }

            return RedirectToAction("Index", "Home");
        }
        public ActionResult UpdateIndex(ScoreModel updatedRecord)
        {
            const string requestUrl = ServiceConfig.DataAccessServicePath + "UpdateRecord";
            var result = ServiceHelper.PostToService<ScoreModel, bool>(requestUrl, updatedRecord);
            // TODO: use result to notify the user if something went wrong ?
            if(result)
            {
                return RedirectToAction("Index", "Home");
            }

            return View(updatedRecord);
        }
        public ActionResult Index(ScoreModel model)
        {
            if(WebSecurity.IsAuthenticated)
            {
                var scoreList = ServiceHelper.GetFromService<ScoreModelList>(ServiceConfig.DataAccessServicePath);

                if (TempData.ContainsKey("ScoreList"))
                {
                    TempData.Remove("ScoreList");
                }
                TempData.Add("ScoreList", scoreList);

                var resultList = scoreList == null ? new List<ScoreModel>() : scoreList.ScoreModelCollection;
                if (model.Type != MatchType.All)
                {
                    resultList = resultList.Where(x => x.Type == model.Type).ToList();
                }

                return View(resultList);
            }

            return RedirectToAction("LoginIndex", "Login");
        }
 public bool UpdateRecord(ScoreModel record)
 {
     return SqlManagment.UpdateRecord(record);
 }
 public bool InsertNewRecords(ScoreModel record)
 {
     return SqlManagment.InsertRecord(record);
 }
Exemple #6
0
        public static bool UpdateRecord(ScoreModel record)
        {
            var connectionString = SqlServerEnvironmentConfig.GetConnectionStringWithWinAuthentication();
            try
            {
                SqlConnection connection;
                using (connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (var command = new SqlCommand("UPDATE dbo.ScoreData SET Date=@Date,TeamVsTeam=@TeamVsTeam,Result=@Result,MatchType=@Matchtype WHERE Id = @Id", connection))
                    {
                        var dateParam = new SqlParameter("@Date", record.Date);
                        var teamVsTeamParam = new SqlParameter("@TeamVsTeam", record.TeamVsTeam);
                        var resultParam = new SqlParameter("@Result", record.Result);
                        var idParam = new SqlParameter("@Id", record.Id);
                        var matchTypeParam = new SqlParameter("@Matchtype", record.Type);

                        command.Parameters.Add(dateParam);
                        command.Parameters.Add(teamVsTeamParam);
                        command.Parameters.Add(resultParam);
                        command.Parameters.Add(idParam);
                        command.Parameters.Add(matchTypeParam);

                        return command.ExecuteNonQuery() != 0;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemple #7
0
        public static bool InsertRecord(ScoreModel record)
        {
            var connectionString = SqlServerEnvironmentConfig.GetConnectionStringWithWinAuthentication();
            try
            {
                SqlConnection connection;
                using (connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (var command = new SqlCommand("INSERT INTO dbo.ScoreData VALUES(@Date,@TeamVsTeam,@Result,@MatchType)", connection))
                    {
                        var date = new SqlParameter("@Date", record.Date);
                        var teamVsTeam = new SqlParameter("@TeamVsTeam", record.TeamVsTeam);
                        var result = new SqlParameter("@Result", record.Result);
                        var matchType = new SqlParameter("@MatchType", record.Result);

                        command.Parameters.Add(date);
                        command.Parameters.Add(teamVsTeam);
                        command.Parameters.Add(result);
                        command.Parameters.Add(matchType);

                        return command.ExecuteNonQuery() != 0;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemple #8
0
        public static ScoreModelList GetGamesData()
        {
            var gameData = new ScoreModelList();
            var connectionString = SqlServerEnvironmentConfig.GetConnectionStringWithWinAuthentication();
            try
            {
                SqlConnection connection;
                using (connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    using (var command = new SqlCommand("SELECT * FROM dbo.ScoreData", connection))
                    {
                        var reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            var dataRow = new ScoreModel
                            {
                                Id = int.Parse(reader["Id"].ToString()),
                                Date = reader["Date"].ToString(),
                                TeamVsTeam = reader["TeamVsTeam"].ToString(),
                                Result = reader["Result"].ToString(),
                                Type = (MatchType) short.Parse(reader["MatchType"].ToString())
                            };

                            gameData.ScoreModelCollection.Add(dataRow);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return gameData;
        }