Beispiel #1
0
        public void AddNewStudent(string name, string surname, int groupId, int specialityId)
        {
            if (specialityId == 0)
            {
                specialityId = _db.Groups.FirstOrDefault(t => t.Id == groupId).SpecialityId;
            }
            UsernameAndPassword usernameAndPassword = new UsernameAndPassword();
            var group     = _db.Groups.FirstOrDefault(t => t.Id == groupId).Name;
            var shortName = "";
            var numbers   = new List <string>()
            {
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
            };

            foreach (var part in group.Split(' '))
            {
                if (numbers.Contains(part[0].ToString()))
                {
                    for (int i = 0; i < part.Length; i++)
                    {
                        if (numbers.Contains(part[i].ToString()))
                        {
                            shortName += part[i];
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    shortName += part.Substring(0, 1);
                }
            }
            var username = usernameAndPassword.TranslitFileName(shortName.ToLower()) + "."
                           + usernameAndPassword.TranslitFileName(name.ToLower()) + "." +
                           usernameAndPassword.TranslitFileName(surname.ToLower());
            var password      = usernameAndPassword.Password();
            var accountsTable = _db.Set <Account>();

            accountsTable.Add(new Account()
            {
                Login = username, Password = password, RoleId = 2
            });
            _db.SaveChanges();

            var last          = _db.Accounts.FirstOrDefault(t => t.Login == username && t.Password == password);
            var studentsTable = _db.Set <Student>();

            studentsTable.Add(new Student()
            {
                SpecialityId = specialityId, GroupId = groupId, Name = name, Surname = surname, AccountId = last.Id
            });
            _db.SaveChanges();
        }
Beispiel #2
0
        public void AddNewLector(string name, string surname)
        {
            UsernameAndPassword usernameAndPassword = new UsernameAndPassword();
            var username = usernameAndPassword.TranslitFileName(name.ToLower()) + "." +
                           usernameAndPassword.TranslitFileName(surname.ToLower());
            var password      = usernameAndPassword.Password();
            var accountsTable = _db.Set <Account>();

            accountsTable.Add(new Account()
            {
                Login = username, Password = password, RoleId = 3
            });
            _db.SaveChanges();

            var last         = _db.Accounts.FirstOrDefault(t => t.Login == username);
            var lectorsTable = _db.Set <Lector>();

            lectorsTable.Add(new Lector()
            {
                Name = name, Surname = surname, AccountId = last.Id
            });
            _db.SaveChanges();
        }