Exemplo n.º 1
0
        public IActionResult ForRegister(Student student)
        {
            StudentAppContext Dbcontext = new StudentAppContext();
            Student           sdt       = new Student();

            sdt.FirstName  = student.FirstName;
            sdt.LastName   = student.LastName;
            sdt.Age        = student.Age;
            sdt.Department = student.Department;
            sdt.Address    = student.Address;
            sdt.City       = student.City;
            sdt.Mail       = student.Mail;
            sdt.Phone      = student.Phone;

            SendMail mail = new SendMail();
            string   pass = mail.SendEmail(student.Mail);

            sdt.Password = pass;


            Dbcontext.Add(sdt);
            Dbcontext.SaveChanges();

            return(View());
        }
        public void EditTask(object sender)
        {
            var listBoxItem = sender as System.Windows.Controls.ListBoxItem; //Get sender

            itemIndex = int.Parse(listBoxItem.Tag.ToString());               //Convert  listBoxItem.Tag to int (TaskID)
            int       itemindex = itemIndex;
            TaskModel task      = Tasks.Where(n => n.TaskID == itemIndex).First();

            itemIndex = Tasks.IndexOf(task);

            IsDialogOpen = true;
            isEditing    = true;

            TaskName        = Tasks[itemIndex].TaskName;
            TaskExplanation = Tasks[itemIndex].TaskExplanation;

            //Modyfikacja w bazie
            using (var context = new StudentAppContext())
            {
                DBTask DBTask = context.DBTasks.Where(x => x.DBTaskId == itemindex).FirstOrDefault(); //Do poprawy idIndex
                DBTask.TaskHeadline = TaskName;
                DBTask.TaskText     = TaskExplanation;

                context.SaveChanges();
            }
        }
        public async Task DeleteGradeAscync(object sender)
        {
            var listBoxItem = sender as System.Windows.Controls.ListBoxItem; //get sender

            gradeIndex = int.Parse(listBoxItem.Tag.ToString());

            var listaPrzedmiotow = Subjects.ToList();

            foreach (SubjectModel przedmiot in listaPrzedmiotow)
            {
                var oceny = przedmiot.Grades.ToList();
                foreach (GradeModel ocena in oceny)
                {
                    if (gradeIndex == ocena.GradeId)
                    {
                        await Task.Delay(200);

                        przedmiot.Grades.Remove(ocena);
                    }
                }
            }

            //Usunięcie oceny z bazy
            using (var context = new StudentAppContext())
            {
                DBMark dbm = context.DBMarks.FirstOrDefault(x => x.DBMarkId == gradeIndex);

                context.DBMarks.Remove(dbm);

                context.SaveChanges();
            }
        }
        public async Task DeleteTaskAsync(object sender)
        {
            var listBoxItem = sender as System.Windows.Controls.ListBoxItem; //Get sender

            itemIndex = int.Parse(listBoxItem.Tag.ToString());               //Convert  listBoxItem.Tag to int (TaskID)
            TaskModel task = Tasks.Where(n => n.TaskID == itemIndex).First();


            await Task.Delay(300); //A short delay to make more smooth animation of removing

            Tasks.Remove(task);    //Get and remove selected task

            /*if (Tasks.Count == 0)
             * {
             *  itemCount = 0;
             * }*/

            //Usuniecie z bazy
            using (var context = new StudentAppContext())
            {
                DBTask DBTask = context.DBTasks.Where(x => x.DBTaskId == itemIndex).FirstOrDefault();
                context.DBTasks.Remove(DBTask);

                context.SaveChanges();
            }
        }
        public void AddNewGrade(string grade, string wage)
        {
            if (!isEditing)
            {
                //Dodanie oceny do bazy danych
                int itemId;
                using (var context = new StudentAppContext())
                {
                    DBSubject dbs    = context.DBSubjects.FirstOrDefault(x => x.SubjectName == chosenSubject.SubjectName);
                    DBMark    dbmark = new DBMark(); //{ Mark = int.Parse(Grade), Date = DateTime.Now, DBSubject = dbs};
                    dbmark.Mark      = double.Parse(Grade);
                    dbmark.Date      = DateTime.Now;
                    dbmark.DBSubject = dbs;
                    dbmark.Subject   = chosenSubject.SubjectName;
                    dbs.Marks.Add(dbmark);
                    //context.Entry(dbs).State = EntityState.Modified;
                    context.SaveChanges();

                    var ostatniObiekt = context.DBMarks.OrderByDescending(x => x.DBMarkId).FirstOrDefault();
                    itemId = ostatniObiekt.DBMarkId;
                }
                chosenSubject.Grades.Add(new GradeModel {
                    GradeId = itemId, Date = DateTime.Now, GradeValue = Convert.ToDouble(Grade), Wage = Convert.ToDouble(Wage), Type = SelectedType
                });
            }
            else
            {
                var listaPrzedmiotow = Subjects.ToList();
                foreach (SubjectModel przedmiot in listaPrzedmiotow)
                {
                    var oceny = przedmiot.Grades.ToList();
                    foreach (GradeModel ocena in oceny)
                    {
                        if (gradeIndex == ocena.GradeId)
                        {
                            ocena.GradeValue = double.Parse(grade);
                            ocena.Wage       = double.Parse(wage);
                            Subjects.Refresh();
                        }
                    }
                }

                //Edycja oceny w bazie danych
                using (var context = new StudentAppContext())
                {
                    DBMark dbm = context.DBMarks.FirstOrDefault(x => x.DBMarkId == gradeIndex);
                    dbm.Mark = double.Parse(grade);
                    context.SaveChanges();
                }

                isEditing = false;
            }

            Grade           = "";
            Wage            = "";
            selectedType    = "inne";
            IsDialogOpen    = false;
            HelperTextGrade = "";
        }
        public async Task LogIn()
        {
            int ok = 1;

            IsDialogProgressOpen = true;
            await Task.Run(() => {
                if (!String.IsNullOrEmpty(Username) && (!String.IsNullOrEmpty(Password)))
                {
                    using (var context = new StudentAppContext())
                    {
                        var users = context.DBUsers.ToList();
                        int flaga = 0;

                        for (int i = 0; i < users.Count; i++)
                        {
                            if (Username.Equals(users[i].Login))
                            {
                                flaga = i;
                                break;
                            }
                        }

                        //return context.DBTasks.ToList();


                        //hasło - savedPasswordHash wczytane z bazy na podstawie nazwy użytkownika/
                        byte[] hashBytes = Convert.FromBase64String(users[flaga].Password);
                        byte[] salt      = new byte[16];

                        Array.Copy(hashBytes, 0, salt, 0, 16);

                        var pbkdf2 = new Rfc2898DeriveBytes(Password, salt, 10000);

                        byte[] hash = pbkdf2.GetBytes(20);


                        for (int i = 0; i < 20; i++)
                        {
                            if (hashBytes[i + 16] != hash[i])
                            {
                                ok = 0;
                            }
                        }
                    }
                }
            });

            if (ok == 1)
            {
                await manager.ShowWindowAsync(new MainWindowViewModel());
                await TryCloseAsync();
            }
            else
            {
                Password = "";
            }
            IsDialogProgressOpen = false;
        }
        public void AddAccount()
        {
            //if(SecureStringToString())

            //byte[] salt;

            //new RNGCryptoServiceProvider().GetBytes(salt = new byte[16]);
            //var pbkdf2 = new Rfc2898DeriveBytes(SecureStringToString(SecurePassword), salt, 10000);

            //byte[] hash = pbkdf2.GetBytes(20);
            //byte[] hashBytes = new byte[36];

            //Array.Copy(salt, 0, hashBytes, 0, 16);
            //Array.Copy(hash, 0, hashBytes, 16, 20);



            if (!String.IsNullOrEmpty(NewUser))
            {
                bool flaga = false;
                using (var context = new StudentAppContext())
                {
                    var users = context.DBUsers.ToList();

                    for (int i = 0; i < users.Count; i++)
                    {
                        if (NewUser.Equals(users[i].Login))
                        {
                            flaga = true;
                            break;
                        }
                    }
                }

                if (NewPassword1.Equals(NewPassword2) && flaga == false)
                {
                    //test_haslo = CreatePasswordHash(NewPassword1);

                    var dbuser = new DBUser {
                        Login = newUser, Password = CreatePasswordHash(NewPassword1)
                    };

                    int userId;
                    using (var context = new StudentAppContext())
                    {
                        context.DBUsers.Add(dbuser);
                        context.SaveChanges();
                        var obiektChwilowy = context.DBUsers.OrderByDescending(x => x.DBUserId).FirstOrDefault();
                        userId = obiektChwilowy.DBUserId;
                    }
                    IsDialogOpen = false;
                }
            }
            //trzeba zapisać savedPasswordHash do bazy
        }
        public GradesWindowViewModel()
        {
            //Pobranie i wyświetlenie przedmiotów i ocen z BD
            using (var context = new StudentAppContext())
            {
                var subjects = context.DBSubjects.ToList();
                foreach (DBSubject dbs in subjects)
                {
                    BindableCollection <GradeModel> gm = new BindableCollection <GradeModel>();
                    if (dbs.Marks != null)
                    {
                        var dbmarks = context.DBMarks.ToList().Where(x => x.DBSubject == dbs);
                        foreach (DBMark mark in dbmarks)
                        {
                            gm.Add(new GradeModel
                            {
                                GradeId    = mark.DBMarkId,
                                Date       = mark.Date,
                                GradeValue = mark.Mark
                            });
                        }
                    }
                    Subjects.Add(new SubjectModel
                    {
                        SubjectName = dbs.SubjectName,
                        Grades      = gm
                    });
                }
            }

            TypesOfGrades.Add("sprawdzian");
            TypesOfGrades.Add("kartkówka");
            TypesOfGrades.Add("odpowiedź ustna");
            TypesOfGrades.Add("zadanie");
            TypesOfGrades.Add("aktywność");
            TypesOfGrades.Add("inne");

            Subjects.Add(new SubjectModel
            {
                SubjectName = "Fizyka",
                Grades      = new BindableCollection <GradeModel>()
                {
                    new GradeModel {
                        Date = DateTime.Now, GradeValue = 5
                    },
                    new GradeModel {
                        Date = DateTime.Now, GradeValue = 2
                    },
                }
            });
        }
        public void AddNewTask()
        {
            if (isEditing)
            {
                Tasks[itemIndex].TaskName        = TaskName;
                Tasks[itemIndex].TaskExplanation = TaskExplanation;
                Tasks.Refresh(); //Raises a change notification indicating that all bindings should be refreshed.

                //Modyfikacja w bazie

                /*
                 * using (var context = new StudentAppContext())
                 * {
                 *  DBTask DBTask = context.DBTasks.Where(x => x.DBTaskId == 4).FirstOrDefault(); //Do poprawy idIndex
                 *  DBTask.TaskHeadline = TaskName;
                 *  DBTask.TaskText = TaskExplanation;
                 *
                 *  context.SaveChanges();
                 * }*/
            }
            else
            {
                //Dodawanie do bazy
                var dbtask = new DBTask {
                    TaskHeadline = taskName, TaskText = taskExplanation
                };
                int itemId;
                using (var context = new StudentAppContext())
                {
                    context.DBTasks.Add(dbtask);
                    context.SaveChanges();
                    var obiektChwilowy = context.DBTasks.OrderByDescending(x => x.DBTaskId).FirstOrDefault();
                    itemId = obiektChwilowy.DBTaskId;
                }

                tasks.Add(new TaskModel {
                    TaskName = taskName, TaskExplanation = taskExplanation, TaskID = itemId
                });
            }

            TaskExplanation = "";
            TaskName        = "";
            IsDialogOpen    = false;
            isEditing       = false;
        }
Exemplo n.º 10
0
        public IActionResult ForLogin(string email, string password)
        {
            StudentAppContext dbContext = new StudentAppContext();
            string            Email     = email;

            string Password = password;
            var    userlist = dbContext.Students.ToList();
            var    user     = userlist.Where(X => X.Mail == email && X.Password == password).FirstOrDefault();

            if (user != null)
            {
                return(View());
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
        public TasksWindowViewModel()
        {
            //Tasks.Add(new TaskModel { TaskName = "Skończyć projekt", TaskExplanation="Skończyć zadanie domowe z programowania", TaskID = itemCount++}); //TODO Показывать название при наведении мышки
            //Tasks.Add(new TaskModel { TaskName = "Styudia", TaskExplanation="Zrobić zadanie z programowania!", TaskID = itemCount++ });
            //Tasks.Add(new TaskModel { TaskName = "Impreza", TaskExplanation="Napić się piwka!", TaskID = itemCount++});

            //Czytanie z bazy i wyświetlenie
            using (var context = new StudentAppContext())
            {
                var tasks = context.DBTasks.ToList();
                foreach (DBTask t1 in tasks)
                {
                    Tasks.Add(new TaskModel {
                        TaskName = t1.TaskHeadline, TaskExplanation = t1.TaskText, TaskID = t1.DBTaskId
                    });
                }

                //return context.DBTasks.ToList();
            }
        }
        public void AddSubject()
        {
            if (NewSubject.Length > 0 && !Subjects.Any(n => n.SubjectName == NewSubject))
            {
                //Zapisanie przedmiotu do bazy danych
                var dbsubject = new DBSubject {
                    SubjectName = newSubject
                };
                using (var context = new StudentAppContext())
                {
                    context.DBSubjects.Add(dbsubject);

                    context.SaveChanges();
                }
                Subjects.Add(new SubjectModel {
                    SubjectName = NewSubject, Grades = new BindableCollection <GradeModel>()
                });
                NewSubject = "";
            }
        }
        public void RemoveSubject()
        {
            if (SelectedItemToRemove != -1)
            {
                var subject = Subjects.ElementAt(SelectedItemToRemove); // pobieram przedmiot do usunięcia
                Subjects.Remove(subject);

                //Usunięcie przedmiotu i jego ocen z bazy
                using (var context = new StudentAppContext())
                {
                    DBSubject dbsubject = context.DBSubjects.FirstOrDefault(x => x.SubjectName == subject.SubjectName);
                    var       dbmarks   = context.DBMarks.ToList().Where(x => x.DBSubject == dbsubject);

                    context.RemoveRange(dbmarks);
                    context.SaveChanges();

                    context.DBSubjects.Remove(dbsubject);
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 14
0
 public StudentsController(StudentAppContext context)
 {
     _context = context;
 }
Exemplo n.º 15
0
 public StudentsRepository(StudentAppContext context)
 {
     _context = context;
 }
Exemplo n.º 16
0
 public EmployeesController(StudentAppContext context)
 {
     _context = context;
 }