private void btnSave_Click(object sender, EventArgs e) { if (ValidateMemberFields(tbxName.Text, tbxSurname.Text, tbxPatronymic.Text, tbxPassport.Text)) { MessageBox.Show("Set all fields."); return; } var unitOfWork = new UnitOfWork(_context); var membershipService = new MembershipService(unitOfWork, unitOfWork); var profileMemberService = new ProfileMemberService(unitOfWork, unitOfWork); if (_isEditMode == false) { try { _member = membershipService.CreateMember(tbxName.Text, tbxSurname.Text, tbxPatronymic.Text, tbxPassport.Text, cmbxRole.SelectedItem.ToString()); _profile = profileMemberService.CreateProfile(tbxAddress.Text, tbxMobile.Text, tbxHome.Text, _member.Id); unitOfWork.Commit(); MessageBox.Show("Successfully added new employee"); Close(); } catch (Exception exception) { unitOfWork.Rollback(); } } else { try { MapToMember(); membershipService.UpdateMember(_member); membershipService.ChangeRole(_member.Id, cmbxRole.SelectedItem.ToString()); if (_profile == null) { _profile = profileMemberService.CreateProfile(tbxAddress.Text, tbxMobile.Text, tbxHome.Text, _member.Id); } else { profileMemberService.UpdateProfile(_profile); } } catch (Exception exception) { unitOfWork.Rollback(); } unitOfWork.Commit(); MessageBox.Show("Successfully edit employee"); Close(); } }
private void ViewEmployee_Load(object sender, System.EventArgs e) { var unitOfWork = new UnitOfWork(_context); var membershipService = new MembershipService(unitOfWork, unitOfWork); var profileMemberService = new ProfileMemberService(unitOfWork, unitOfWork); var meetingService = new MeetingService(unitOfWork, unitOfWork); _member = membershipService.GetMemberById(_memberId); _profile = profileMemberService.GetProfileByMemberId(_member.Id); SetDataToControls(); var commissions = membershipService.GetCommissionsOfMember(_member.Id); var meetings = meetingService.GetMeetingsOfMemberParticipate(_member.Id); dgvCommissions.DataSource = commissions; dgvMeetings.DataSource = meetings; unitOfWork.Commit(); }
private void AddChangeEmployee_Load(object sender, EventArgs e) { var unitOfWork = new UnitOfWork(_context); var membershipService = new MembershipService(unitOfWork, unitOfWork); var roles = membershipService.GetAllRoles(); if (_memberId != 0) { var profileMemberService = new ProfileMemberService(unitOfWork, unitOfWork); _member = membershipService.GetMemberById(_memberId); _profile = profileMemberService.GetProfileByMemberId(_member.Id); SetValuesForControls(_member, roles, _profile); unitOfWork.Commit(); } else { cmbxRole.DataSource = roles; unitOfWork.Commit(); } }