public void Copy(SportEvent sportEvent) { EventId = sportEvent.EventId; SportId = sportEvent.SportId; EventName = sportEvent.EventName; EventDate = sportEvent.EventDate; Team1Price = sportEvent.Team1Price; DrawPrice = sportEvent.DrawPrice; Team2Price = sportEvent.Team2Price; }
public static void Modify(this SportEventsContext contextEvent, SportEvent sportEvent) { var result = contextEvent.Events.SingleOrDefault(b => b == sportEvent); if (result == null) { return; } result.Copy(sportEvent); contextEvent.SaveChanges(); }
public static SportEvent ToSportEvent(this string inputString) { var data = inputString.Split('\n', StringSplitOptions.RemoveEmptyEntries); var sportEvent = new SportEvent(); var properties = sportEvent.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var command in data) { var commands = command.Split(new[] { '-', ' ' }, StringSplitOptions.RemoveEmptyEntries); var property = properties.Single(x => x.Name == commands[0]); property.SetValue(sportEvent, Convert.ChangeType(string.Join(' ', commands.Skip(1)), property.PropertyType)); } return(sportEvent); }