Esempio n. 1
0
        public MainViewModel()
        {
            DateTime bd = new DateTime(2000, 8, 24);

            _dm      = new DataManager();
            Students = new ObservableCollection <Student>()
            {
                new Student("Andrey", "Ublin", bd, "IN-101")
            };
            StudSorter = new StudentSort();
            AddCommand = new RelayCommand(x =>
            {
                Students.Add(new Student("Null", "Null", new DateTime(1, 1, 1), "Null"));
            });
            RemoveCommand  = new RelayCommand(x => Students.Remove(SelectedStudent), x => Students.Count > 0 && SelectedStudent != null);
            OpenCommand    = new RelayCommand(x => _dm.OpenFile(Students));
            SaveCommand    = new RelayCommand(x => _dm.SaveFile(Students));
            SortCollection = new RelayCommand(x =>
            {
                StudSorter.Decrease  = Decrese;
                StudSorter.Byname    = ByName;
                StudSorter.Bysurname = BySurnane;
                StudSorter.Bydate    = ByDate;
                StudSorter.Bygroup   = ByGroup;
                StudSorter.Sort(Students);
            });
        }
Esempio n. 2
0
        public List <Student> ToList(StudentSort sort)
        {
            switch (sort)
            {
            case StudentSort.Id:
                m_Students.Sort(delegate(Student s1, Student s2) { return(s1.Id.CompareTo(s2.Id)); });
                break;

            case StudentSort.Firstname:
                m_Students.Sort(delegate(Student s1, Student s2) { return(String.Compare(s1.Firstname, s2.Firstname)); });
                break;

            case StudentSort.Surname:
                m_Students.Sort(delegate(Student s1, Student s2) { return(String.Compare(s1.Surname, s2.Surname)); });
                break;
            }

            return(m_Students);
        }
Esempio n. 3
0
        private void TeacherListSort(StudentSort sortBy)
        {
            List <StudentListItemViewModel> newList;

            switch (sortBy)
            {
            case StudentSort.Name:
                newList = StudentList.OrderBy(x => x.Student.Name).ToList();
                StudentListSortLabel = "Name";
                break;

            case StudentSort.Nickname:
                newList = StudentList.OrderBy(x => x.Student.Nickname).ToList();
                StudentListSortLabel = "Nickname";
                break;

            case StudentSort.School:
                newList = StudentList.OrderBy(x => x.Student.School).ToList();
                StudentListSortLabel = "School";
                break;

            case StudentSort.Grade:
                newList = StudentList.OrderBy(x => x.Student.Grade).ToList();
                StudentListSortLabel = "Grade";
                break;

            case StudentSort.Status:
                newList = StudentList.OrderBy(x => x.Student.Status).ToList();
                StudentListSortLabel = "Status";
                break;

            default:
                newList = StudentList.OrderBy(x => x.Student.Student_ID).ToList();
                StudentListSortLabel = "ID";
                break;
            }
            if (newList != null)
            {
                StudentList = newList;
            }
        }
Esempio n. 4
0
        public async Task <HttpResponseMessage> GetStudentsAsync([FromUri] StudentFilter filter, [FromUri] StudentSort sort, [FromUri] StudentPage page)
        {
            if (filter != null && !filter.EmptyFilterString())
            {
                filter.StringToNameAndSurname();
            }
            StudentList = await studentService.ReadDataAsync(filter, sort, page);

            if (StudentList.Count() == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            Students = mapper.Map <List <Student> >(StudentList);

            return(Request.CreateResponse(HttpStatusCode.OK, Students));
        }
Esempio n. 5
0
        public async Task <List <StudentModel> > ReadDataAsync(StudentFilter filter, StudentSort sort, StudentPage page)
        {
            StudentList = await studentRepository.ReadStudentAsync(filter, sort, page);

            return(StudentList);
        }
Esempio n. 6
0
        public async Task <List <StudentModel> > ReadStudentAsync(StudentFilter filter, StudentSort sort, StudentPage page)
        {
            string connectionString = @"Data Source = (LocalDB)\MSSQLLocalDB;Initial Catalog = PraksaSQL; Integrated Security = True";

            int begginingRow = 1;
            int endRow       = 11;

            if (page != null)
            {
                begginingRow = (page.PageNumber - 1) * page.PageSize;
                endRow       = begginingRow + page.PageSize + 1;
            }

            string queryString =
                "DECLARE @BegginingRow INT = " + begginingRow + ";" +
                "DECLARE @EndRow INT = " + endRow + ";";

            queryString +=
                "SELECT id,ime,prezime FROM (" +
                "SELECT ROW_NUMBER() OVER(ORDER BY id) AS RowNum, id, ime, prezime " +
                "FROM STUDENT" +
                ") AS tbl " +
                "WHERE @BegginingRow < RowNum AND @EndRow > RowNum ";


            if (filter != null)
            {
                if (!filter.EmptyFilterString())
                {
                    string FilterString = "'" + String.Join("','", filter.StudentNames) + "'";
                    queryString += "AND (ime IN (" + FilterString + ") OR (prezime IN (" + FilterString + ")))";
                }
            }

            if (sort != null)
            {
                queryString += " ORDER BY " + sort.OrderBy + " " + sort.Order;
            }
            else
            {
                queryString += " ORDER BY prezime asc";
            }

            using (SqlConnection connection =
                       new SqlConnection(connectionString))
            {
                SqlCommand command =
                    new SqlCommand(queryString, connection);
                await connection.OpenAsync();

                SqlDataReader reader = await command.ExecuteReaderAsync();

                // Call Read before accessing data.
                while (await reader.ReadAsync())
                {
                    StudentList.Add(new StudentModel {
                        id = reader.GetGuid(0), name = reader.GetString(1), surname = reader.GetString(2)
                    });
                }

                // Call Close when done reading.
                reader.Close();

                return(StudentList);
            }
        }