public IHttpActionResult GetAddNewEnrollment(int courseId)
        {
            if (courseId == null || courseId == 0)
            {
                return StatusCode(HttpStatusCode.NotFound);
            }
            var statucosde = HttpStatusCode.NotModified;
            using (StoreContext context = new StoreContext())
            {
                if (User.Identity.IsAuthenticated)
                {
                    Student currentStudent = context.Students.Where(q => q.UserName == User.Identity.Name).FirstOrDefault();
                    if (currentStudent != null)
                    {
                        if (context.Enrollments.Where(q => q.StudentId == currentStudent.StudentId && q.CourseId == courseId).FirstOrDefault() == null)
                        {
                            context.Enrollments.Add(new Enrollment { CourseId = courseId, StudentId = currentStudent.StudentId });
                            context.SaveChanges();
                            statucosde = HttpStatusCode.OK;
                        }
                    }
                }
            }

            return StatusCode(statucosde);
        }
        private ContosoMobileAppMSA.Models.ExchangeSet DataForMobileApp()
        {
            List<ContosoMobileAppMSA.Models.Course> coursesForSend = new List<ContosoMobileAppMSA.Models.Course>();
            List<ContosoMobileAppMSA.Models.CourseActivity> activitiesForSend = new List<ContosoMobileAppMSA.Models.CourseActivity>();
            List<ContosoMobileAppMSA.Models.Enrollment> enrollments = new List<ContosoMobileAppMSA.Models.Enrollment>();
            List<ContosoMobileAppMSA.Models.TrainingHistory> trainingHistories = new List<ContosoMobileAppMSA.Models.TrainingHistory>();
            using (StoreContext context = new StoreContext())
            {
                coursesForSend = context.Courses
                    .Select(q => new ContosoMobileAppMSA.Models.Course
                    {
                        CourseId = q.CourseId,
                        CourseTitle = q.CourseTitle,
                        Credits = q.Credits
                    }).ToList();
                activitiesForSend = context.CourseActivities
                                               .Select(q => new ContosoMobileAppMSA.Models.CourseActivity
                                               {
                                                   ActivityName = q.ActivityName,
                                                   CourseActivityId = q.CourseActivityId,
                                                   ActivityType = q.ActivityTypeRef.ActivityTypeName,
                                                   CourseId = q.CourseId

                                               })
                                               .ToList();
                if (User.Identity.IsAuthenticated)
                {
                    Student currentStudent = context.Students.Where(q => q.UserName == User.Identity.Name).FirstOrDefault();
                    if (currentStudent != null)
                    {
                        enrollments = context.Enrollments.Where(q => q.StudentId == currentStudent.StudentId)
                                        .Select(q => new ContosoMobileAppMSA.Models.Enrollment
                                        {
                                            CourseId = q.CourseId,
                                            EnrollmentId = q.EnrollmentId,
                                            GradeTitle = q.GradeRef.GradeTitle,
                                            StudentId = q.StudentId
                                        }).ToList();
                        trainingHistories = context.TrainingHistories.Where(q => q.StudentId == currentStudent.StudentId)
                                    .Select(q => new ContosoMobileAppMSA.Models.TrainingHistory
                                    {
                                        CourseActivityId = q.CourseActivityId,
                                        GradeTitle = q.GradeRef.GradeTitle,
                                        TrainingHistoryId = q.TrainingHistoryId
                                    }).ToList();
                    }
                }

            }

            ContosoMobileAppMSA.Models.ExchangeSet result = new ContosoMobileAppMSA.Models.ExchangeSet();
            result.Courses = coursesForSend;
            result.CourseActivities = activitiesForSend;
            result.Enrollments = enrollments;
            result.TrainingHistories = trainingHistories;
            return result;
        }
        // data for Admin chart
        private ListsForChart UsersAndRoles()
        {
            ListsForChart listForChart = new ListsForChart();
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            string query = "(select ur.RoleId  Label, count(distinct ur.UserId) Value "
                                                                + "from userroles ur "
                                                                + "group by ur.RoleId) union "
                                                                + "(select 'Student' Label, count(distinct Id) Value "
                                                                + "from users "
                                                                + "where Id not in (select UserId from userroles))";
            using (StoreContext context = new StoreContext())
            {
                var result = context.Database.SqlQuery<ChartElement>(query, parameters).ToList();

                listForChart.Labels = new List<string>(result.Select(q => q.Label).ToList());
                listForChart.DataSets = new Dictionary<string, List<int>>()
                    { { "Amount of users", new List<int>(result.Select(q => q.Value).ToList()) } };
            }
            return listForChart;
        }
        // data for teacher chart
        private ListsForChart StudetsAndCourses()
        {
            ListsForChart listForChart = new ListsForChart();
            using (StoreContext context = new StoreContext())
            {
                var result = context.Enrollments.GroupBy(q => q.CourseRef)
                    .Select(n => new ChartElement
                    {
                        Label = n.Key.CourseTitle,
                        Value = n.Count()//(w => w.StudentRef.Di)
                    })
                    .ToList();

                    listForChart.Labels = new List<string>(result.Select(q=>q.Label).ToList());
                    listForChart.DataSets= new Dictionary<string, List<int>>()
                    { { "Amount of students", new List<int>(result.Select(q => q.Value).ToList()) } };
            }
            return listForChart;
        }
        // data for student chart
        private ListsForChart GradesForActivities()
        {
            ListsForChart listForChart = new ListsForChart();
            using (StoreContext context = new StoreContext())
            {
                var result = context.TrainingHistories.Where(q => q.StudentRef.UserName == User.Identity.Name)
                    .GroupBy(q => q.GradeRef)
                    .Select(n => new ChartElement
                    {
                        Label = n.Key.GradeTitle,
                        Value = n.Count()//(w => w.StudentRef.Di)
                    })
                    .ToList();

                listForChart.Labels = new List<string>(result.Select(q => q.Label).ToList());
                listForChart.DataSets = new Dictionary<string, List<int>>()
                    { { "Amount of grades", new List<int>(result.Select(q => q.Value).ToList()) } };
            }
            return listForChart;
        }
        public ActionResult Index()
        {
            ViewBag.CurrentStudentName = "";
            if (User.Identity.IsAuthenticated && !User.IsInRole("Admin") && !User.IsInRole("Teacher"))
            {
                Student currentStudent = null;
                using (StoreContext context = new StoreContext())
                {
                    currentStudent = context.Students.Where(q => q.UserName == User.Identity.Name).FirstOrDefault();
                }
                if (currentStudent != null)//find in studets user
                {
                    ViewBag.CurrentStudentName = currentStudent.UserName;
                }
                else
                {
                    ViewBag.CurrentStudentName = "newStudent";
                }
            }

            return View();
        }