public IActionResult PostSportCountry([FromBody] SportCountry sportCountry) { try { if (sportCountry != null) { _logger.LogInformation("API Request hit: INSERT SportCountry : "); var result = _countryRepository.AddSportCountry(sportCountry); if (result == 0) { return(Ok("{\"status\": \"Success\"}")); } else { _logger.LogInformation("API Request (INSERT SportCountry : ) not committed"); return(NotFound("Failed: INSERT could not commit")); } } else { _logger.LogInformation("API Request hit (INSERT SportCountry) with null entry"); return(BadRequest("Failed: null entry")); } } catch (Exception e) { _logger.LogError("API Request (INSERT SportCountry) FAILED: ", e); return(BadRequest("Failed")); } }
public bool IsExistingSportCountry(SportCountry sportCountry) { var isExistRecord = _context.SportCountry .Where(x => x.SportId == sportCountry.SportId && x.CountryId == sportCountry.CountryId).ToList(); return(isExistRecord.Count == 0); }
public IActionResult UpdateSportCountry([FromBody] SportCountry sportCountry) { try { if (sportCountry != null) { _logger.LogInformation("API Request hit: UPDATE SportCountry : " + sportCountry.SportCountryId); var result = _sportTreeRepository.UpdateSportCountry(sportCountry); if (result == 0) { return(Ok("{\"status\": \"Success\"}")); } else { _logger.LogInformation("API Request (UPDATE SportCountry : " + sportCountry.SportCountryId + " ) not committed"); return(NotFound("Failed: UPDATE could not commit")); } } else { _logger.LogInformation("API Request hit (UPDATE SportCountry) with null entry"); return(BadRequest("Failed: null entry")); } } catch (Exception e) { _logger.LogError("API Request (UPDATE SportCountry) FAILED: ", e); return(BadRequest("Failed")); } }
public IActionResult AddSportInCountry(SportCountry sportCountry) { try { if (sportCountry != null) { var results = _sportCountryService.Add(sportCountry); if (results == false) { return(Ok("You can not link a sport with country more than once ")); } else { _logger.LogInformation("Post Api Call on SportCountry table successesfull"); return(Ok("Record succesfullly added")); } } else { _logger.LogError("Post call on SportCountry Table failed"); return(BadRequest("There was an error trying to process your request")); } } catch (Exception ex) { return(BadRequest($"There was an error trying to process your request {ex}")); throw; } }
public int UpdateSportCountry(SportCountry entity) { using (var connection = DBService.GetSqlConnection()) { var result = connection.Execute($"EXECUTE dbo.UpdateSportCountry {entity.SportCountryId},{entity.SportId},{entity.CountryId}"); return(result + 1); } }
public bool UpdateSportCountry(SportCountry sportCountry) { using (var connection = DatabaseService.SqlConnection()) { var parameters = new { sportCountry.SportCountryId , sportCountry.SportId, sportCountry.CountryId }; return(connection.Execute("sp_UpdateSportCountry", parameters, commandType: CommandType.StoredProcedure) < 0); } }
public bool Add(SportCountry sportCountry) { if (_associationsBsLogic.IsExistingSportCountry(sportCountry) == false) { return(false); } else { _sportCountry.Add(sportCountry); return(true); } }
public bool AddSportCountryMapping(SportCountry sportCountry) { using (var connection = DatabaseService.SqlConnection()) { var parameters = new { sportCountry.CountryId, sportCountry.SportId }; var result = connection.Execute("sp_SportCountry", parameters, commandType: CommandType.StoredProcedure); return(result < 0); } }
public RedirectToActionResult Add(int id) { var session = new SportCountrySession(HttpContext.Session); var countries = session.GetMyCountries(); bool alreadyin = false; SportCountry country = context.SportCountries.Find(id); SportGame game = context.SportGames.Find(country.GameId); country.Game = game; SportType type = context.SportTypes.Find(country.SportTypeId); SportCategory category = context.SportCategories.Find(type.CategoryId); type.Category = category; country.SportType = type; foreach (var lc in countries) { if (lc.CountryId == id) { alreadyin = true; } } if (alreadyin == false) { countries.Add(country); session.SetMyCountries(countries); var cookies = new SportCountryCookies(Response.Cookies); cookies.SetMyCountriesIds(countries); TempData["message"] = $"{country.Name} added to your favorites"; } else { TempData["message"] = $"{country.Name} is already in your favorites"; } return(RedirectToAction("sportTest", new { activeGame = session.GetActiveGame(), activeCategory = session.GetActiveCategory() })); }
public ViewResult sportFavoriteDetail(int id) { var session = new SportCountrySession(HttpContext.Session); ViewBag.ActiveGame = session.GetActiveGame(); ViewBag.ActiveCategory = session.GetActiveCategory(); SportCountry country = context.SportCountries.Find(id); SportGame game = context.SportGames.Find(country.GameId); country.Game = game; SportType type = context.SportTypes.Find(country.SportTypeId); SportCategory category = context.SportCategories.Find(type.CategoryId); type.Category = category; country.SportType = type; return(View(country)); }
public int Add(SportCountry entity) { int rowAffected = 0; using (var connection = DbService.sqlConnection()) { if (connection.State == ConnectionState.Closed) { connection.Open(); } DynamicParameters parameters = new DynamicParameters(); parameters.Add("@SportId", entity.SportId); parameters.Add("@CountryId", entity.CountryId); rowAffected = connection.Execute("InSertSportCountry", parameters, commandType: CommandType.StoredProcedure); } return(rowAffected); }
public IActionResult Update(int?sportCountryId, SportCountry sportCountry) { try { if (sportCountryId.HasValue && sportCountryId == sportCountry.SportCountryId) { _logger.LogInformation("Put Request: Successfull"); _sportCountryService.Update(sportCountry); return(Ok("Record successfully updated")); } else { return(BadRequest("There was an error processing your request")); } } catch (Exception ex) { _logger.LogError("Put Request: Request failed", ex); return(BadRequest($"There was an error processing {ex}")); } }
public IActionResult PutSportCountry([FromBody] SportCountry sportCountry) { try { if (sportCountry.Equals(null)) { return(BadRequest("Oops something went wrong.")); // if there was no value entered of sportId it will return a bad request. } var result = _sportTree.UpdateSportCountry(sportCountry); // searches the table using the given idea and if the item is found and updated it will return true if (result) { return(StatusCode(200, StatusCodes.ReturnStatusObject("Successfully Updated"))); } else { return(StatusCode(400, StatusCodes.ReturnStatusObject("Update Failed."))); } } catch (Exception e) { return(StatusCode(400, StatusCodes.ReturnStatusObject("Update Failed."))); } }
public IActionResult AddSportCountryMapping([FromBody] SportCountry sportCountry) { try { if (sportCountry.Equals(null)) { return(StatusCode(400, StatusCodes.ReturnStatusObject("No input provided."))); } var result = _sportTree.AddSportCountryMapping(sportCountry); if (result) { return(StatusCode(200, StatusCodes.ReturnStatusObject("Successfully Added."))); } else { return(StatusCode(400, StatusCodes.ReturnStatusObject("Insert has Failed."))); } } catch (Exception e) { return(StatusCode(400, StatusCodes.ReturnStatusObject("Insert has Failed. " + e.Message))); } }
public void Update(SportCountry sportCountry) { _context.Entry(sportCountry).State = EntityState.Modified; _context.SaveChanges(); }
public void Add(SportCountry sportCountry) { _context.SportCountry.Add(sportCountry); _context.SaveChanges(); }
public void Update(SportCountry sportCountry) { _sportCountry.Update(sportCountry); }
public int Put([FromBody] SportCountry sportCountry) { return(_sportcountry.Update(sportCountry)); }
public int Post([FromBody] SportCountry sportCountry) { return(_sportcountry.Add(sportCountry)); }