public ActionResult RemoveSubjectsForSelectedDegree(IEnumerable <Guid> subjects, string selectedDegID, string degree)
        {
            if (degree != null)
            {
                //int degID = int.Parse(degree);
                Guid degID = Guid.Parse(degree);

                Degree_Program deg = r.Degree_Program.Where(s => s.ProgramID == degID).Select(s => s).FirstOrDefault();
                ViewBag.DegreeSelected = deg;
                ViewBag.DegreeName     = deg.Degree_ProgramName;
                var getSubjects = r.Degree_Subject.OrderBy(s => s.ID).Where(s => s.DegreeID == degID).Select(s => s);
                return(View(getSubjects));
            }
            else
            {
                if (subjects != null)
                {
                    try
                    {
                        //int degID = int.Parse(selectedDegID);
                        Guid degID = Guid.Parse(degree);

                        Degree_Program        getDegree    = r.Degree_Program.Where(s => s.ProgramID == degID).Select(s => s).FirstOrDefault();
                        List <Degree_Subject> listToDelete = r.Degree_Subject.Where(s => subjects.Contains(s.SubjectID.Value) &&
                                                                                    s.DegreeID == getDegree.ProgramID).ToList();
                        if (CoursesModel.DeleteRelatedBPSRecordsOnDeletionOfSubjects(listToDelete))
                        {
                            foreach (var item in listToDelete)
                            {
                                r.Degree_Subject.Remove(item);
                            }
                            r.SaveChanges();
                            ViewBag.DegreeSelected = getDegree.Degree_ProgramName;
                            ViewBag.Message        = "Succesfully Subjects Removed";
                            return(View(listToDelete));
                        }
                        else
                        {
                            ViewBag.DegreeSelected = getDegree.Degree_ProgramName;
                            ViewBag.Message        = "Unable To Delete Subjects";
                            return(View(listToDelete));
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                else
                {
                    ViewBag.Message = "Plz Select A Degree First";
                    return(View());
                }
            }
        }
        public ActionResult AddSubjectsForSelectedDegree(IEnumerable <Guid> subjects, string selectedDegID, string degree)
        {
            if (degree != null)
            {
                Guid           degID = Guid.Parse(degree);
                Degree_Program deg   = r.Degree_Program.Where(s => s.ProgramID == degID).Select(s => s).FirstOrDefault();
                ViewBag.DegreeSelected = deg;
                ViewBag.DegreeName     = deg.Degree_ProgramName
                ;
                var getSubjects = r.Subjects.OrderBy(s => s.SubjectID).Select(s => s);
                return(View(getSubjects));
            }
            else
            {
                if (subjects != null)
                {
                    //int degID = int.Parse(selectedDegID);
                    Guid degID = Guid.Parse(degree);

                    Degree_Program getDegree = r.Degree_Program.Where(s => s.ProgramID == degID).Select(s => s).FirstOrDefault();

                    List <Subject> listToDelete = r.Subjects.Where(s => subjects.Contains(s.SubjectID)).ToList();

                    if (CoursesModel.CheckToSeeIfThereExistARecordWithSameDegreeNameAndSubject(getDegree, listToDelete))
                    {
                        foreach (var item in listToDelete)
                        {
                            r.Degree_Subject.Add(new Degree_Subject
                            {
                                DegreeID  = getDegree.ProgramID,
                                SubjectID = item.SubjectID,
                                ID        = Guid.NewGuid()
                            });
                        }
                        r.SaveChanges();
                        ViewBag.DegreeSelected = getDegree.Degree_ProgramName;
                        ViewBag.Message        = "Succesfully Subjects Assigned";
                        return(View(listToDelete));
                    }
                    else
                    {
                        ViewBag.Message = "The Degree " + getDegree.Degree_ProgramName + " has already assigned some Selected Subjects";
                        return(View(listToDelete));
                    }
                }
                else
                {
                    ViewBag.Message = "Plz Select A Degree First";
                    return(View());
                }
            }
        }
Exemplo n.º 3
0
 public bool CheckToSeeIfThereExistARecordWithSameDegreeNameAndSubject(Degree_Program deg, IEnumerable <Subject> subj)
 {
     foreach (var item in subj)
     {
         foreach (var item2 in rc.Degree_Subject)
         {
             if (item.SubjectID == item2.SubjectID && item2.DegreeID == deg.ProgramID)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
        public ActionResult AddDegreeRecords(Degree_Program deg, string level)
        {
            if (level == "Select")
            {
                ViewBag.Message = "Error! Unable to Add Record!" + " Plz Select a Valid Degree level";
                var AlltheLevels = r.Levels.Select(s => s).OrderBy(s => s.LevelID);
                ViewBag.Levels = AlltheLevels;
                return(View());
            }
            else
            {
                Guid levelID = Guid.Parse(level);
                deg.LevelID = levelID;
                deg.Level   = r.Levels.Where(s => s.LevelID == levelID).Select(s => s).FirstOrDefault();

                if (CoursesModel.AddCourse(levelID, deg))
                {
                    ViewBag.Message = "Successfully Record Added";
                    var AlltheLevels = r.Levels.Select(s => s).OrderBy(s => s.LevelID);
                    ViewBag.Levels = AlltheLevels;
                    return(View());
                }
                else
                {
                    ViewBag.Message = "Error! Unable to Add Record! " + deg.Degree_ProgramName + " Already Exists";
                    var AlltheLevels = r.Levels.Select(s => s).OrderBy(s => s.LevelID);
                    ViewBag.Levels = AlltheLevels;
                    return(View());
                }

                //}
                //else
                //{
                //    foreach (var item in ModelState)
                //    {
                //        ViewBag.M2 = item.Key;
                //        ViewBag.M1 = item.Value;
                //    }
                //    ViewBag.Message = "Error! Unable to Add Record!";
                //    var AlltheLevels = r.Levels.Select(s => s).OrderBy(s => s.LevelID);
                //    ViewBag.Levels = AlltheLevels;
                //    return View();
                //}
            }
        }
Exemplo n.º 5
0
 public bool DeleteAllSubjects(Degree_Program deg, int part)
 {
     using (TransactionScope t = new TransactionScope())
     {
         try
         {
             foreach (var item in rc.Degree_Subject)
             {
                 if (item.DegreeID == deg.ProgramID && item.Part == part)
                 {
                     rc.Degree_Subject.Remove(item);
                 }
             }
             rc.SaveChanges();
             t.Complete();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Exemplo n.º 6
0
 public bool AddCourse(Guid level, Degree_Program deg)
 {
     //int degID = 0;
     try
     {
         //var getDegree = rc.Degree_Program.OrderByDescending(s => s.ProgramID).Select(s => s).FirstOrDefault();
         //if (getDegree != null)
         //{
         //    degID = getDegree.ProgramID;
         //    degID++;
         //}
         //else
         //{
         //    degID++;
         //}
         //deg.ProgramID = degID;
         deg.Level   = rc.Levels.Where(s => s.LevelID == level).Select(s => s).FirstOrDefault();
         deg.LevelID = level;
         //var getSameRecords=rc.Degree_Program.Any(s=>s.Degree_ProgramName==deg.Degree_ProgramName);
         if (rc.Degree_Program.Any(s => s.Degree_ProgramName == deg.Degree_ProgramName &&
                                   s.LevelID == deg.LevelID))
         {
             return(false);
         }
         else
         {
             deg.ProgramID = Guid.NewGuid();
             rc.Degree_Program.Add(deg);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 7
0
        public bool AssignNewSubjects(List <Subject> listToDelete,
                                      List <Degree_Subject> getDegreeSubjects, Degree_Program deg, int part)
        {
            bool checker = true;

            foreach (var item in listToDelete)
            {
                foreach (var item2 in getDegreeSubjects)
                {
                    //Check If the Subject is already assigned
                    if (item.SubjectID == item2.SubjectID)
                    {
                        checker = false;
                        break;
                    }
                }

                if (checker == true)
                {
                    //If not Assign The subject
                    rc.Degree_Subject.Add(new Degree_Subject
                    {
                        Degree_Program = deg,
                        Subject        = rc.Subjects.Where(s => s.SubjectID == item.SubjectID).Select(s => s).FirstOrDefault(),
                        DegreeID       = deg.ProgramID,
                        SubjectID      = item.SubjectID,
                        ID             = Guid.NewGuid(),
                        Part           = part
                    });
                    checker = false;
                }
                checker = true;
            }
            rc.SaveChanges();
            return(true);
        }
Exemplo n.º 8
0
        //Subject Updation in Degree Subjects

        public string SubjectAddToDegree(IEnumerable <Guid> subj, Guid degID, int part)
        {
            try
            {
                //int degreeID = int.Parse(degID);

                //Get List of All the selected Subjects
                List <Subject> listToDelete = rc.Subjects.Where(s => subj.Contains(s.SubjectID)).ToList();

                //Get Degree Program Reference
                Degree_Program deg = rc.Degree_Program.Where(s => s.ProgramID == degID).Select(s => s).FirstOrDefault();

                //Get All the assigned Subjects to DegreeProgram
                List <Subject> getAllTheSubjectOfTheDegree = rc.Degree_Subject
                                                             .Where(s => s.DegreeID == degID &&
                                                                    s.Part == part).Select(s => s.Subject).ToList();


                //Get Records from Degree_Subject Table for the particular degree program
                List <Degree_Subject> getDegreeSubjects = rc.Degree_Subject
                                                          .Where(s => s.DegreeID == degID &&
                                                                 s.Part == part).Select(s => s).ToList();

                //foreach (var item in subj)
                //{
                //    if (getDegreeSubjects.Any(s=>s.SubjectID==item && s.Part==part))
                //    {
                //        return "Subject with Name: "+rc.Subjects.Where(s=>s.SubjectID==item).Select(s=>s.SubjectName).FirstOrDefault()??""
                //            +" already exists in part "+part;
                //    }
                //}
                //Match Subjects That are same in both the new selection and the old subjects in degree
                var JoinedSubjectInDegreeAndSelectedSubjects = from subjOfDegree in getAllTheSubjectOfTheDegree
                                                               join selectedSubjects in listToDelete
                                                               on subjOfDegree.SubjectID equals selectedSubjects.SubjectID
                                                               orderby selectedSubjects.SubjectID
                                                               select selectedSubjects;
                //Get All the Subjects that are different
                var deleteUnMatchedOrDifferentSubjects =
                    getDegreeSubjects.Where(s => !subj.Contains(s.SubjectID.Value) && s.Part == part)
                    .Select(s => s);
                //var deleteUnMatchedOrDifferentSubjects = from selectedSubjects in listToDelete
                //                                         from subjOfDegree in getDegreeSubjects
                //                                         where(subjOfDegree.SubjectID != selectedSubjects.SubjectID)
                //                                         select subjOfDegree;

                if (JoinedSubjectInDegreeAndSelectedSubjects.Count() == 0)
                {
                    foreach (var item in getDegreeSubjects)
                    {
                        rc.Degree_Subject.Remove(item);
                    }
                    rc.SaveChanges();

                    foreach (var item in listToDelete)
                    {
                        rc.Degree_Subject.Add(
                            new Degree_Subject
                        {
                            Degree_Program = deg,
                            DegreeID       = deg.ProgramID,
                            Subject        = item,
                            SubjectID      = item.SubjectID,
                            ID             = Guid.NewGuid(),
                            Part           = part
                        });
                    }
                    rc.SaveChanges();
                    return("OK");
                }
                else if (JoinedSubjectInDegreeAndSelectedSubjects.Count() == getAllTheSubjectOfTheDegree.Count())
                {
                    if (AssignNewSubjects(listToDelete, getDegreeSubjects, deg, part))
                    {
                        return("OK");
                    }
                    else
                    {
                        return("Unable to Update Subjects!");
                    }
                }
                else
                {
                    //Remove previous subjects that are different
                    foreach (var item in deleteUnMatchedOrDifferentSubjects)
                    {
                        rc.Degree_Subject.Remove(item);
                    }
                    rc.SaveChanges();
                    if (AssignNewSubjects(listToDelete, getDegreeSubjects, deg, part))
                    {
                        return("OK");
                    }
                    else
                    {
                        return("Unable to Update Subjects!");
                    }
                }
                #region Old Code
                //    bool checker = true;

                //    foreach (var item in getAllTheSubjectOfTheDegree)
                //    {
                //        foreach (var item2 in listToDelete)
                //        {
                //            //Check If the Subject is already assigned
                //            if (item.SubjectID == item2.SubjectID)
                //            {
                //                checker = false;
                //                break;
                //            }
                //        }

                //        if (checker == true)
                //        {
                //            //If not Assign The subject
                //            rc.Degree_Subject.Add(new Degree_Subject
                //            {
                //                Degree_Program = deg,
                //                Subject = rc.Subjects.Where(s => s.SubjectID == item.SubjectID).Select(s => s).FirstOrDefault(),
                //                DegreeID = degreeID,
                //                SubjectID = item.SubjectID
                //            });
                //            checker = false;
                //        }
                //    }
                //    rc.SaveChanges();
                //    t.Complete();
                //    return "OK";
                //}
                #endregion
            }
            catch
            {
                return("Unable to Update Subjects!");
            }
        }