public void create(gymnast gymnast) { using (var db = new DataContext()) { bool dbexist = db.Database.Exists(); if (dbexist == true) { db.gymnast.Add(gymnast); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } }
public void update(gymnast gymnast) { using (var db = new DataContext()) { bool dbexist = db.Database.Exists(); if (dbexist == true) { var query = from qGymnast in db.gymnast where qGymnast.gymnast_id == gymnast.gymnast_id select qGymnast; foreach (gymnast eGymnast in query) { eGymnast.turnbondID = gymnast.turnbondID; eGymnast.gender = gymnast.gender; eGymnast.nationality = gymnast.nationality; eGymnast.length = gymnast.length; eGymnast.weight = gymnast.weight; eGymnast.picture = gymnast.picture; eGymnast.birthdate = gymnast.birthdate; eGymnast.name = gymnast.name; eGymnast.surname = gymnast.surname; eGymnast.surname_prefix = gymnast.surname_prefix; eGymnast.note = gymnast.note; } try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } }
public void NewGymnast(object commandParam) { selectedFilterItem = null; EditName = ""; EditPrefix = ""; EditSurname = ""; EditFIGNumber = ""; EditDateOfBirth = ""; EditNationality = ""; EditGender = ""; EditLength = ""; EditWeight = ""; EditMemos = ""; EditPicture = null; PictureCommandVisible = Visibility.Visible; EnableFilter = false; inEditingMode = true; creatingNewGymnast = true; OnPropertyChanged("Fullname"); OnPropertyChanged("IsEditing"); OnPropertyChanged("IsNotEditing"); OnPropertyChanged("PictureAvailable"); OnPropertyChanged("SelectedFilterItem"); OnPropertyChanged("EditPictureAvailable"); }
public void SaveChanges(object commandParam) { decimal tmpLength; decimal tmpWeight; DateTime tmpDoB; String[] formats = { "yyyy/dd/MM", "yyyy/dd/M", "yyyy/d/MM", "yyyy/d/M", "dd/MM/yyyy", "dd/M/yyyy", "d/MM/yyyy", "d/M/yyyy" }; gymnast gymnast = creatingNewGymnast ? new gymnast() : SelectedFilterItem; gymnast.name = EditName; gymnast.surname_prefix = EditPrefix; gymnast.surname = EditSurname; gymnast.turnbondID = long.Parse(EditFIGNumber); gymnast.birthdate = DateTime.TryParseExact(EditDateOfBirth, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out tmpDoB) ? tmpDoB : (DateTime?)null; gymnast.nationality = EditNationality; gymnast.gender = EditGender; gymnast.length = decimal.TryParse(EditLength.Replace(",", "."), out tmpLength) ? tmpLength : (decimal?)null; gymnast.weight = decimal.TryParse(EditWeight.Replace(",", "."), out tmpWeight) ? tmpWeight : (decimal?)null; gymnast.note = EditMemos; //gymnast.picture = EditPicture; if (EditPicture != null) { BitmapImage bImage = EditPicture as BitmapImage; byte[] data = null; //large picture JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bImage)); using (MemoryStream ms = new MemoryStream()) { encoder.Save(ms); data = ms.ToArray(); gymnast.picture = data; } //small picture bImage.DecodePixelHeight = 32; bImage.DecodePixelWidth = 32; encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bImage)); using (MemoryStream ms = new MemoryStream()) { encoder.Save(ms); data = ms.ToArray(); gymnast.picture_small = data; } } if (creatingNewGymnast) { // Create a new Gymnast uModule.create(gymnast); selectedFilterItem = null; Name = ""; Prefix = ""; Surname = ""; FIGNumber = ""; DateOfBirth = ""; Nationality = ""; Gender = ""; Length = ""; Weight = ""; Memos = ""; Picture = null; } else { // update gymnast uModule.update(gymnast); SelectedFilterItem = gymnast; // re-setting selected filter. Should update appropriate fields. } CancelChanges(null); // returns to non editing mode EnableFilter = true; inEditingMode = false; gymnastList = uModule.getGymnastCollection(); applyFilter(); OnPropertyChanged("FilterList"); OnPropertyChanged("Fullname"); OnPropertyChanged("IsEditing"); OnPropertyChanged("IsNotEditing"); OnPropertyChanged("PictureAvailable"); OnPropertyChanged("SelectedFilterItem"); OnPropertyChanged("EditPictureAvailable"); }
public void DeleteGymnast(object commandParam) { if (!_app.IsLoggedIn) { _app.ShowLoginView(); } if (_app.IsLoggedIn && SelectedFilterItem != null) { MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { uModule.delete(SelectedFilterItem.gymnast_id); selectedFilterItem = null; Name = ""; Prefix = ""; Surname = ""; FIGNumber = ""; DateOfBirth = ""; Nationality = ""; Gender = ""; Length = ""; Weight = ""; Memos = ""; Picture = null; EnableFilter = true; inEditingMode = false; gymnastList = uModule.getGymnastCollection(); applyFilter(); OnPropertyChanged("FilterList"); OnPropertyChanged("Fullname"); OnPropertyChanged("IsEditing"); OnPropertyChanged("IsNotEditing"); OnPropertyChanged("PictureAvailable"); OnPropertyChanged("SelectedFilterItem"); OnPropertyChanged("EditPictureAvailable"); } } }