private void BtnSTsave_Click(object sender, EventArgs e)
        {
            int affectedRows = 0;

            using (Modelss.AKADEMIYAEntities2 db = new Modelss.AKADEMIYAEntities2())
            {
                groupp.Id = db.Groups.Where(g => g.Name == cbgroups.Text).FirstOrDefault().Id;



                //db.Tasks.Where(t => t.GroupId == groupp.Id).FirstOrDefault();
                Modelss.Task grpTask = new Modelss.Task();

                grpTask.Name     = txtTask.Text;
                grpTask.Deadline = Convert.ToDateTime(tdedline.Text);
                grpTask.GroupId  = groupp.Id;
                grpTask.Status   = true;
                db.Tasks.Add(grpTask);

                affectedRows = db.SaveChanges();
                txtTask.Text = tdedline.Text = cbgroups.Text = "";
            }
            if (affectedRows > 0)
            {
                MessageBox.Show("Submitted");
                return;
            }
            else
            {
                MessageBox.Show("Not Submitted !!");
                return;
            }
        }
 private void GenerateTasks()
 {
     using (Modelss.AKADEMIYAEntities2 db = new Modelss.AKADEMIYAEntities2())
     {
         dvgsmark2.Rows.Clear();
         List <Modelss.Student> students = db.Students.Where(s => s.GroupId == _groupID).ToList();
         foreach (var item in students)
         {
             List <Modelss.StudentsMark> studentsMark = db.StudentsMarks.Where(sm => sm.StudentId == item.Id && sm.TaskId == _taskID).ToList();
             Modelss.Task task     = item.Group.Tasks.FirstOrDefault(t => t.Id == _taskID);
             string       taskName = "";
             int          taskMark = 0;
             if (task != null)
             {
                 taskName = task.Name;
                 Modelss.StudentsMark smark = task.StudentsMarks.FirstOrDefault(sm => sm.StudentId == item.Id);
                 if (smark != null)
                 {
                     taskMark = smark.Mark;
                 }
             }
             dvgsmark2.Rows.Add(item.Id, task.Id, item.Name, item.Surname, taskName, taskMark);
         }
     }
 }