Esempio n. 1
0
        private void SaveStudent()
        {
            Users existingUser = UsersDal.FindAll(x => (x.Email == SelectedStudent.Users.Email || x.NEPTUN == SelectedStudent.Users.NEPTUN) && x.ID != SelectedStudent.UserID).FirstOrDefault();

            if (existingUser != null)
            {
                MessageBox.Show("Létezik már felhasználó ezzel a Neptun-kóddal vagy E-mail címmel!", "Hiba", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                if (this._contextDal.FindById(SelectedStudent.ID) == null)
                {
                    this.SelectedStudent.Users.FullName     = String.Format("{0} {1}", SelectedStudent.Users.LastName, SelectedStudent.Users.FirstName);
                    this.SelectedStudent.Users.UserName     = SelectedStudent.Users.Email;
                    this.SelectedStudent.Users.UserPassword = UsersDAL.ComputeSha256Hash(SelectedStudent.Users.Email);

                    Users u = SelectedStudent.Users;
                    u.IsPasswordChangeRequired = true;
                    this.UsersDal.Create(u);
                    SelectedStudent.UserID = u.ID;
                    u.Student.Add(SelectedStudent);
                    this.UsersDal.Update(u);
                    MailSender.SendMail(u.Email);
                }
                else
                {
                    this.SelectedStudent.Users.FullName = String.Format("{0} {1}", SelectedStudent.Users.LastName, SelectedStudent.Users.FirstName);
                    Team studentTeamCaptain = _contextDal.applicationDbContext.Team.FirstOrDefault(x => x.TeamCaptain == SelectedStudent.ID);
                    if (studentTeamCaptain != null && studentTeamCaptain.ID != SelectedStudent.TeamID)
                    {
                        studentTeamCaptain.TeamCaptain = null;
                        TeamDAL td = new TeamDAL();
                        td.Update(studentTeamCaptain);
                        SelectedStudent.Team = null;
                    }
                    this.UsersDal.Update(SelectedStudent.Users);
                    this._contextDal.Update(SelectedStudent);
                }
                this.SourceWindow.Close();
            }
        }
Esempio n. 2
0
        private void ImportStudents()
        {
            bool         duplicateError      = false;
            bool         sessionGroupMissing = false;
            bool         teamMissing         = false;
            List <Users> userList            = new List <Users>();

            foreach (DataRow item in Table.Rows)
            {
                userList.Add((Users)item["User"]);
            }
            var NEPTUNDuplicates = userList.GroupBy(x => x.NEPTUN).Select(c => new { Key = c.Key, total = c.Count() });
            var MailDuplicates   = userList.GroupBy(x => x.Email).Select(c => new { Key = c.Key, total = c.Count() });

            foreach (var item in NEPTUNDuplicates)
            {
                if (item.total > 1)
                {
                    duplicateError = true;
                    break;
                }
            }
            foreach (var item in MailDuplicates)
            {
                if (item.total > 1)
                {
                    duplicateError = true;
                    break;
                }
            }

            UsersDAL        ud  = new UsersDAL();
            SessionGroupDAL sgd = new SessionGroupDAL();
            TeamDAL         td  = new TeamDAL();

            foreach (DataRow item in Table.Rows)
            {
                Users  rowUser          = ((Users)item["User"]);
                string sessiongroupName = (string)item["SessionGroup"];
                string teamName         = (string)item["Team"];
                duplicateError = duplicateError || ud.FindAll().Exists(x => x.Email == rowUser.Email);
                duplicateError = duplicateError || ud.FindAll().Exists(x => x.Email == rowUser.NEPTUN);

                SessionGroup sg = sgd.FindAll(x => x.Semester.IsActive && x.SessionGroupName == sessiongroupName).FirstOrDefault();
                sessionGroupMissing = sessionGroupMissing || (sg == null);
                teamMissing         = teamMissing || sessionGroupMissing;
                if (!teamMissing)
                {
                    Team t = td.FindAll(x => x.SessionGroupID == sg.ID && x.TeamName == teamName).FirstOrDefault();
                    teamMissing = teamMissing || (t == null);
                }
            }
            string errorMessage = "";

            if (duplicateError)
            {
                errorMessage += "\nAz állományban több azonos, vagy a rendszerben már szereplő E-mail cím vagy NEPTUN kód szerepel!";
            }
            if (sessionGroupMissing)
            {
                errorMessage += "\nAz állományban nem létező csoport szerepel!";
            }
            if (teamMissing)
            {
                errorMessage += "\nAz állományban nem létező csapat szerepel!";
            }
            if (!String.IsNullOrEmpty(errorMessage))
            {
                MessageBox.Show("Hiba az importált adatokban!" + errorMessage, "Hiba", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                foreach (DataRow item in Table.Rows)
                {
                    string       sessionGroupName = (string)item["SessionGroup"];
                    string       teamName         = (string)item["Team"];
                    SessionGroup sg = sgd.FindAll(x => x.Semester.IsActive && x.SessionGroupName == sessionGroupName).FirstOrDefault();
                    Team         t  = td.FindAll(x => x.SessionGroupID == sg.ID && x.TeamName == teamName).FirstOrDefault();
                    Student      st = new Student()
                    {
                        TeamID = t.ID
                    };
                    Users u = (Users)item["User"];
                    u.IsPasswordChangeRequired = true;
                    ud.Create(u);
                    st.UserID = u.ID;
                    u.Student.Add(st);
                    ud.Update(u);
                    MailSender.SendMail(u.Email);
                }
                MessageBox.Show("Sikeres importálás!", "", MessageBoxButton.OK);
                this.Close();
            }
        }