public void UpdateAdditionalRelations(string relationInfo, int relationId) { using (StudentsDbContext db = new StudentsDbContext()) { try { ParentsInfo ChangeRelationInfo = db.ParentsInfos?.Where(x => x.Relation.Id == relationId).FirstOrDefault(); ChangeRelationInfo.Relation.Name = relationInfo; db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/* * public void UpdateParents(List<ParentsInfo> parents) * { * } */ public void UpdateParents(string motherName, string motherLastName, string motherWorkPlace, string fatherName, string fatherLastName, string fatherWorkPlace, int motherId, int fatherId) { using (StudentsDbContext db = new StudentsDbContext()) { try { ParentsInfo ChangeMotherInfo = db.ParentsInfos.Where(x => x.Id == motherId).FirstOrDefault(); ParentsInfo ChangeFatherInfo = db.ParentsInfos.Where(x => x.Id == fatherId).FirstOrDefault(); ChangeMotherInfo.FirstName = motherName; ChangeMotherInfo.LastName = motherLastName; ChangeMotherInfo.WorkPlace = motherWorkPlace; ChangeFatherInfo.FirstName = fatherName; ChangeFatherInfo.LastName = fatherLastName; ChangeFatherInfo.WorkPlace = fatherWorkPlace; db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void AddMainInfo_btn_Click(object sender, EventArgs e) // Add main info student { try { using (StudentsServiceAppClient client = new StudentsServiceAppClient()) { Phone newPhone = new Phone(); newPhone.PhoneNumber = MobTelField.Text; List <Phone> phone = new List <Phone>(); phone.Add(newPhone); StudentProgress newProgress = new StudentProgress(); newProgress.Progress = float.Parse(ProgressAddField.Text); Adress newAdress = new Adress(); newAdress.Address = AddressAddField.Text; Group newGroup = new Group(); newGroup.Speciality = GroupAddField.Text; Phone newParentsPhone = new Phone(); newParentsPhone.PhoneNumber = PhonesRelatonsAddFielad.Text; List <Phone> relationsPhones = new List <Phone>(); relationsPhones.Add(newParentsPhone); ParentsInfo newMotheInfo = new ParentsInfo(); ParentsInfo newFatherInfo = new ParentsInfo(); Relation newRelationInfo = new Relation(); newRelationInfo.Name = RelationField.Text; newMotheInfo.FirstName = MotherNameField.Text; newMotheInfo.LastName = MotherLastNameField.Text; newMotheInfo.WorkPlace = MotherWorkPlace.Text; newMotheInfo.Relation = newRelationInfo; newMotheInfo.Phones = relationsPhones; newFatherInfo.FirstName = FatherNameField.Text; newFatherInfo.LastName = FatherLastNameField.Text; newFatherInfo.WorkPlace = FatherWorkPlaseField.Text; newFatherInfo.Relation = newRelationInfo; List <ParentsInfo> parents = new List <ParentsInfo>(); parents.Add(newMotheInfo); parents.Add(newFatherInfo); //parents.Add(newRelationInfo); StudentInfo newStudentInfo = new StudentInfo { FirstName = NameField.Text, LastName = LastNameField.Text, Surname = surnameAddField.Text, NumberRecordBook = Convert.ToInt32(NumbRecBookAddField.Text), Sex = SexField.Text, Age = Convert.ToInt32(AgeField.Text), Birthdate = DateTime.Parse(DateOfBirthField.Text), StudentPhones = phone, StudentProgress = newProgress, Adress = newAdress, Group = newGroup, ParentsInfo = parents, }; client.AddNewStudent(newStudentInfo); client.Close(); } string message = "Студент був доданий"; string caption = "Додання студента до БД"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBox.Show(message, caption, button); } catch (Exception ex) { string message = ex.Message; string caption = "Помилка!"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBox.Show(message, caption, button); } }