Exemplo n.º 1
0
        public static Object GetRegularObject(Type type, Object o, bool continueDeserializing = true)
        {
            Object return_object = null;
            if (type == typeof(DegreeProgram))
            {
                SerializableModels.DegreeProgram dp = (SerializableModels.DegreeProgram) o;

                DegreeProgram newItem = new DegreeProgram
                {
                    ID = dp.ID,
                    degreeProgramName = dp.degreeProgramName,
                    degreeProgramDescription = dp.degreeProgramDescription,
                };

                if (dp.requiredCourses != null && dp.electiveCourses != null)
                {
                    newItem.requiredCourses = new List<RequiredCourse>();
                    newItem.electiveCourses = new List<ElectiveCourse>();
                    foreach (SerializableModels.RequiredCourse rc in dp.requiredCourses)
                    {
                        newItem.requiredCourses.Add((RequiredCourse)GetRegularObject(typeof(RequiredCourse), rc, true));
                    }
                    foreach (SerializableModels.ElectiveCourse ec in dp.electiveCourses)
                    {
                        newItem.electiveCourses.Add((ElectiveCourse)GetRegularObject(typeof(ElectiveCourse), ec, true));
                    }
                }

                return_object = newItem;
            }
            else if (type == typeof(RequiredCourse))
            {
                SerializableModels.RequiredCourse rq = (SerializableModels.RequiredCourse) o;

                RequiredCourse newItem = new RequiredCourse
                {
                    ID = rq.ID,
                    courseID = rq.courseID,
                    degreeProgramID = rq.degreeProgramID,
                    semester = rq.semester,
                };

                newItem.course = (Course)GetRegularObject(typeof(Course), rq.course, true);

                return_object = newItem;
            }
            else if (type == typeof(ElectiveCourse))
            {
                SerializableModels.ElectiveCourse eq = (SerializableModels.ElectiveCourse) o;

                ElectiveCourse newItem = new ElectiveCourse
                {
                    ID = eq.ID,
                    electiveListID = eq.electiveListID,
                    degreeProgramID = eq.degreeProgramID,
                    semester = eq.semester,
                    credits = eq.credits,
                };

                newItem.electiveList = (ElectiveList)GetRegularObject(typeof(ElectiveList), eq.electiveList, true);

                return_object = newItem;
            }
            else if (type == typeof(Course))
            {
                SerializableModels.Course c = (SerializableModels.Course) o;

                Course newItem = new Course
                {
                    ID = c.ID,
                    coursePrefix = c.coursePrefix,
                    courseNumber = c.courseNumber,
                    courseTitle = c.courseTitle,
                    courseDescription = c.courseDescription,
                    minHours = c.minHours,
                    maxHours = c.maxHours,
                    undergrad = c.undergrad,
                    graduate = c.graduate,
                    variable = c.variable,
                };

                if (continueDeserializing)
                {
                    List<PrerequisiteCourse> prereqsList = new List<PrerequisiteCourse>();
                    List<PrerequisiteCourse> prereqsForList = new List<PrerequisiteCourse>();
                    foreach (SerializableModels.PrerequisiteCourse pc in c.prerequisites)
                    {
                        prereqsList.Add((PrerequisiteCourse)GetRegularObject(typeof(PrerequisiteCourse), pc, true));
                    }
                    foreach (SerializableModels.PrerequisiteCourse pc in c.prerequisiteFor)
                    {
                        prereqsForList.Add((PrerequisiteCourse)GetRegularObject(typeof(PrerequisiteCourse), pc, true));
                    }
                    newItem.prerequisites = prereqsList.ToArray();
                    newItem.prerequisiteFor = prereqsForList.ToArray();
                }

                return_object = newItem;
            }
            else if (type == typeof(ElectiveList))
            {
                SerializableModels.ElectiveList eList = (SerializableModels.ElectiveList) o;

                ElectiveList newItem = new ElectiveList
                {
                    ID = eList.ID,
                    electiveListName = eList.electiveListName,
                    shortName = eList.shortName,
                };

                return_object = newItem;
            }
            else if (type == typeof(ElectiveListCourse))
            {
                SerializableModels.ElectiveListCourse elc = (SerializableModels.ElectiveListCourse) o;

                ElectiveListCourse newItem = new ElectiveListCourse
                {
                    ID = elc.ID,
                    courseID = elc.courseID,
                    electiveListID = elc.electiveListID,
                    course = (Course)GetRegularObject(typeof(Course), elc.course, true),
                };

                return_object = newItem;
            }
            else if (type == typeof(PrerequisiteCourse))
            {
                SerializableModels.PrerequisiteCourse pc = (SerializableModels.PrerequisiteCourse) o;

                PrerequisiteCourse newItem = new PrerequisiteCourse
                {
                    ID = pc.ID,
                    prerequisiteCourseID = pc.prerequisiteCourseID,
                    prerequisiteForCourseID = pc.prerequisiteForCourseID,
                    prerequisiteCourse = (Course)GetRegularObject(typeof(Course),pc.prerequisiteCourse,false),
                    prerequisiteForCourse = (Course)GetRegularObject(typeof(Course), pc.prerequisiteForCourse, false),
                };

                return_object = newItem;
            }
            else if (type == typeof(Plan))
            {
                SerializableModels.Plan plan = (SerializableModels.Plan) o;

                Plan newItem = new Plan
                {
                    ID = plan.ID,
                    planName = plan.planName,
                    degreeProgramID = plan.degreeProgramID,
                    userID = plan.userID,
                    semesterID = plan.semesterID,
                    semester = plan.semester,
                };

                if (continueDeserializing)
                {
                    newItem.degreeProgram = (DegreeProgram)GetRegularObject(typeof(DegreeProgram), plan.degreeProgram, false);
                    newItem.user = (User)GetRegularObject(typeof(User), plan.user, true);
                    List<PlanCourse> planCourses = new List<PlanCourse>();
                    foreach (SerializableModels.PlanCourse planCourse in plan.planCourses)
                    {
                        planCourses.Add((PlanCourse)GetRegularObject(typeof(PlanCourse), planCourse, true));
                    }
                    newItem.planCourses = planCourses.ToArray();
                }

                return_object = newItem;
            }
            else if (type == typeof(User))
            {
                SerializableModels.User user = (SerializableModels.User) o;

                User newItem = new User
                {
                    ID = user.ID,
                    username = user.username,
                    realName = user.realName,
                };

                if (continueDeserializing && user.plans != null)
                {
                    List<Plan> plans = new List<Plan>();
                    foreach (SerializableModels.Plan plan in user.plans)
                    {
                        plans.Add((Plan)GetRegularObject(typeof(Plan), plan, false));
                    }
                }

                return_object = newItem;
            }
            else if (type == typeof(PlanCourse))
            {
                SerializableModels.PlanCourse pc = (SerializableModels.PlanCourse) o;

                PlanCourse newItem = new PlanCourse
                {
                    ID = pc.ID,
                    notes = pc.notes,
                    planID = pc.planID,
                    courseID = pc.courseID,
                    electiveListID = pc.electiveListID,
                    semesterID = pc.semesterID,
                    order = pc.order,
                    semester = pc.semester,
                    credits = pc.credits,
                };

                if (continueDeserializing)
                {
                    newItem.plan = (Plan)GetRegularObject(typeof(Plan), pc.plan, false);
                    if (pc.course.courseDescription != null)
                    {
                        newItem.course = (Course)GetRegularObject(typeof(Course), pc.course, true);
                    }
                    newItem.electiveList = (ElectiveList)GetRegularObject(typeof(ElectiveList), pc.electiveList, false);
                }

                return_object = newItem;
            }
            else
            {
                throw new NotImplementedException();
            }
            return return_object;
        }
Exemplo n.º 2
0
        public ActionResult Edit(User user, string[] userRoleCheck)
        {
            if (ModelState.IsValid)
            {
                if (webSecurity.CurrentUser.Identity.Name.Equals(user.username) || webSecurity.CurrentUser.IsInRole("Administrator"))
                {
                    users.UpdateValues(users.Find(user.ID), user);
                    users.SaveChanges();

                    if (webSecurity.CurrentUser.IsInRole("Administrator"))
                    {
                        List<String> rolesList = roles.GetAllRoles().ToList();
                        List<string> usersRoles = roles.GetRolesForUser(user.username).ToList();
                        List<string> userNewRoles = userRoleCheck.ToList();
                        foreach (string role in rolesList)
                        {
                            if (usersRoles.Contains(role))
                            {
                                if (!userNewRoles.Contains(role))
                                {
                                    roles.RemoveUserFromRole(user.username, role);
                                }
                            }
                            else
                            {
                                if (userNewRoles.Contains(role))
                                {
                                    roles.AddUserToRole(user.username, role);
                                }
                            }
                        }
                        return RedirectToAction("Index");
                    }
                    return RedirectToAction("Manage", "Accounts");
                }
            }
            return View(user);
        }
 private User createTempUser()
 {
     User user = new User()
     {
         ID = 3,
         username = "******",
         realName = "Test User 3"
     };
     return user;
 }