Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            pmsstoreEntities entties = new pmsstoreEntities();

            foreach (var j in this.checkedListBox1.CheckedItems)
            {
                tbl_Student    studentItem  = (tbl_Student)j;
                tbl_CSLecturer lecturerItem = (tbl_CSLecturer)this.listBox1.SelectedItem;
                int            sessionId    = Convert.ToInt32(this.comboBox1.SelectedValue);
                //check if the student has been allocated to any lecturer before in selected session
                var queryCheck = (from p in entties.tbl_Allocation
                                  where p.StudentID == studentItem.GUID && p.SessionID == sessionId
                                  select p).FirstOrDefault();
                if (queryCheck != null)
                {
                    //this student is already assigned to this or another lecturer this session, therefore continue to the next student
                    continue;
                }


                tbl_Allocation allocation = new tbl_Allocation();
                allocation.DateAllocated = DateTime.Now;
                allocation.LecturerID    = lecturerItem.GUID;
                allocation.SessionID     = Convert.ToInt32(this.comboBox1.SelectedValue);
                allocation.StudentID     = studentItem.GUID;

                entties.tbl_Allocation.Add(allocation);
            }
            entties.SaveChanges();
        }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            pmsstoreEntities entties = new pmsstoreEntities();

            foreach (var j in this.checkedListBox1.CheckedItems)
            {
                tbl_Student    studentItem  = (tbl_Student)j;
                tbl_CSLecturer lecturerItem = (tbl_CSLecturer)this.listBox1.SelectedItem;
                int            sessionId    = Convert.ToInt32(this.comboBox1.SelectedValue);
                //check if the student has been allocated to any lecturer before in selected session
                var queryCheck = (from p in entties.tbl_Allocation
                                  where p.StudentID == studentItem.GUID && p.SessionID == sessionId
                                  select p).FirstOrDefault();
                if (queryCheck != null)
                {
                    //remove
                    entties.tbl_Allocation.Remove(queryCheck);
                }
            }
            entties.SaveChanges();
            RefreshItems();
        }