public bool CreateEventLocation(EventLocationModel location) { MySqlTransaction trans = null; bool success; try { this.Connection.Open(); trans = this.Connection.BeginTransaction(); const string InsertString = @"insert into event_location (max_players, postal_code, city, street, house_number) values (@max_players, @postal_code, @city, @street, @house_number);"; MySqlCommand command = new MySqlCommand(InsertString, this.Connection) { Parameters = { new MySqlParameter("@max_players", MySqlDbType.Int32) { Value = location.MaxPlayers }, new MySqlParameter("@postal_code", MySqlDbType.VarChar) { Value = location.PostalCode }, new MySqlParameter("@city", MySqlDbType.VarChar) { Value = location.City }, new MySqlParameter("@street", MySqlDbType.VarChar) { Value = location.Street }, new MySqlParameter("@house_number", MySqlDbType.VarChar) { Value = location.HouseNumber } } }; command.Prepare(); command.ExecuteNonQuery(); trans.Commit(); success = true; } catch (Exception e) { success = false; trans?.Rollback(); Console.WriteLine("Adding location failed. " + e.Message); MessageBox.Show("Locatie toevoegen is mislukt."); } finally { this.Connection.Close(); } return(success); }
public IActionResult AddLocation() { EventLocationModel newLocation = new EventLocationModel { Id = Guid.NewGuid().ToString(), LocationName = "Location", Goal = 2000, GoalStatus = 0 }; return(PartialView("~/Views/Shared/EditorTemplates/EventLocationModel.cshtml", newLocation)); }
private async Task <int> UpdateEventLocationGoalValue(string eventId, string locationId, int value) { EventModel eventObj = await _eventRestService.GetEvent(eventId); if (eventObj != null) { EventLocationModel eventLocation = eventObj.EventLocations?.Find(p => p.Id == locationId); if (eventLocation != null && eventObj.IsEventActive) { eventLocation.GoalStatus += value; try { var result = await _eventRestService.UpdateEvent(eventObj); if (result == HttpStatusCode.OK) { return(eventLocation.GoalStatus); } else if (result == HttpStatusCode.PreconditionFailed) { await UpdateEventLocationGoalValue(eventId, locationId, value); //Etag error, retrying... } else { _logger.LogError($"UpdateEventLocationGoalValue: {result}"); return(-1); } } catch (Exception e) { _logger.LogError($"UpdateEventLocationGoalValue: {e.Message}"); return(-1); } } } else { _logger.LogError($"The event {eventId} wasn't found."); } return(-1); }
public EventLocationModel GetEventLocation(int locationId) { EventLocationModel eventLocation = null; try { this.Connection.Open(); string query = $@"SELECT * FROM event_location WHERE id = {locationId}"; MySqlCommand cmd = new MySqlCommand(query, this.Connection); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { eventLocation = new EventLocationModel { Id = reader.GetInt32("id"), MaxPlayers = reader.GetInt32("max_players"), PostalCode = reader.GetString("postal_code"), City = reader.GetString("city"), Street = reader.GetString("street"), HouseNumber = reader.GetString("house_number") }; } } catch (Exception e) { Console.WriteLine("Fetching tournaments failed. " + e.Message); MessageBox.Show("Toernooien ophalen is mislukt."); } finally { this.Connection.Close(); } return(eventLocation); }