Exemplo n.º 1
0
        public ActionResult DeleteCourseFromPersonalArea(int courseId)
        {
            string       userId = User.Identity.GetUserId();
            PersonalArea area   = db.PersonalAreas.Where(p => p.AspNetUserId.CompareTo(userId) == 0).First();
            // area.Courses.Remove(db.Courses.Find(courseId));
            //
            CourseStructure corStr = area.CourseStructures.Where(c => c.IdCourse == courseId).First();

            area.CourseStructures.Remove(area.CourseStructures.Where(c => c.IdCourse == courseId).First());
            db.CourseStructures.Remove(corStr);
            area.Courses.Remove(db.Courses.Find(courseId));
            db.Entry(area).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            CoursesInAreaModel coursesModel = MakeCoursesModel(area);

            ViewBag.coursesModel = coursesModel;
            List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >();

            foreach (var course in area.Courses)
            {
                StudyViewModel studyModel = GetNextParagraph(area, course.Id);
                redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse));
            }
            ViewBag.RedGreen = redGreen;
            return(View(area));
        }
Exemplo n.º 2
0
		public Tuple<CourseStructure,List<VideoPublishSummary>> Commit()
		{
			var result = new CourseStructure();
            var videos = new List<VideoPublishSummary>();
			Commit(Root[0], result,videos);
			result.RootTopic = Root[0].Topic;
            return Tuple.Create(result, videos);
		}
Exemplo n.º 3
0
 public ActionResult AddCourseToArea(int courseId)
 {
     if (User.Identity.IsAuthenticated)
     {
         ViewBag.teacher = false;
         if (User.IsInRole("teacher"))
         {
             PersonalArea areaTeacher = new PersonalArea()
             {
                 AspNetUserId = User.Identity.GetUserId(), Person = User.Identity.Name
             };
             ViewBag.teacher = true;
             return(View(areaTeacher));
         }
         string       userId       = User.Identity.GetUserId();
         PersonalArea area         = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId) == 0).First();
         bool         alreadyStudy = false;
         foreach (var course in area.Courses)
         {
             if (course.Id == courseId)
             {
                 alreadyStudy = true;
             }
         }
         if (alreadyStudy)
         {
             CoursesInAreaModel coursesModel1 = MakeCoursesModel(area);
             ViewBag.coursesModel = coursesModel1;
             List <KeyValuePair <int, int> > redGreen1 = new List <KeyValuePair <int, int> >();
             foreach (var course in area.Courses)
             {
                 StudyViewModel studyModel = GetNextParagraph(area, course.Id);
                 redGreen1.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse));
             }
             ViewBag.RedGreen = redGreen1;
             return(View(area));
         }
         CourseStructure courseStr = CreateCourseStructure(courseId);
         area.CourseStructures.Add(courseStr);
         area.Courses.Add(db.Courses.Find(courseId));
         db.SaveChanges();
         CoursesInAreaModel coursesModel = MakeCoursesModel(area);
         ViewBag.coursesModel = coursesModel;
         List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >();
         foreach (var course in area.Courses)
         {
             StudyViewModel studyModel = GetNextParagraph(area, course.Id);
             redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse));
         }
         ViewBag.RedGreen = redGreen;
         return(View(area));
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
Exemplo n.º 4
0
        public CourseStructure CreateCourseStructure(int courseId)
        {
            Course          course          = db.Courses.Find(courseId);
            CourseStructure courseStructure = new CourseStructure();

            courseStructure.IdCourse = course.Id;
            List <ParagraphStructure> listParag = new List <ParagraphStructure>();
            var paragraphs = db.Paragraphs.Where(p => p.CourseId == courseId).ToList();

            foreach (var par in paragraphs)
            {
                List <TestStructure> tests = new List <TestStructure>();
                var t = db.Tests.Where(te => te.ParagraphId == par.Id).ToList();
                foreach (var test in t)
                {
                    var           questions     = db.Questions.Where(q => q.TestId == test.Id);
                    TestStructure testStructure = new TestStructure()
                    {
                        NumQuestion = questions.Count(), IdTest = test.Id, NumInParagraph = test.NumInParagraph
                    };
                    List <QuestionStructure> queStructure = new List <QuestionStructure>();
                    foreach (var que in questions)
                    {
                        QuestionStructure q = new QuestionStructure()
                        {
                            Passed = false, NumInTest = que.NumInTest, IdQuestion = que.Id
                        };
                        queStructure.Add(q);
                    }
                    testStructure.QuestionStructures = queStructure;
                    db.TestStructures.Add(testStructure);
                    tests.Add(testStructure);
                }
                ParagraphStructure paragraphStructure = new ParagraphStructure()
                {
                    NumTest = tests.Count, Tests = tests, IdParagraph = par.Id, NumInCourse = par.NumInCourse
                };
                db.ParagraphStructures.Add(paragraphStructure);
                listParag.Add(paragraphStructure);
            }
            courseStructure.NumParagraph = listParag.Count();
            courseStructure.Paragraphs   = listParag;
            db.CourseStructures.Add(courseStructure);
            db.SaveChanges();
            return(courseStructure);
        }
Exemplo n.º 5
0
		public void Commit(TopicWrap wrap, CourseStructure structure, List<VideoPublishSummary> videos)
		{
			wrap.Topic.Items.Clear();
			foreach (var e in wrap.Items)
			{
				if (e is TopicWrap)
				{
					var tw = e as TopicWrap;
					Commit(tw,structure,videos);
					wrap.Topic.Items.Add(tw.Topic);
					continue;
				}
				if (e is VideoWrap)
				{
					var vw = e as VideoWrap;
					var relation = new VideoToTopicRelation();
					relation.TopicGuid = wrap.Topic.Guid;
					relation.NumberInTopic = wrap.Items.IndexOf(vw);
					relation.VideoGuid = vw.Video.Guid;
					structure.VideoToTopicRelations.Add(relation);
                    videos.Add(vw.Video);
				}
			}
		}
        /// <summary>
        /// Build CourseListResponseStructure object from CourseListResponse data and original CourseListRequestStructure.
        /// </summary>
        /// <param name="response">CourseListResponse data.</param>
        /// <param name="request">Original CourseListRequestStructure.</param>
        /// <returns>Populated CourseListResponseStructure object.</returns>
        private static CourseListResponseStructure BuildCourseListResponseStructure(CourseListResponse response, CourseListRequestStructure request)
        {
            CourseListResponseStructure courseListResponse = new CourseListResponseStructure();

            // Create matching Ldcs collection
            List <CourseListResponseStructureMatchingLDCS> matchingLdcss =
                new List <CourseListResponseStructureMatchingLDCS>();

            foreach (LdcsCode ldcsCode in response.LdcsCodes)
            {
                CourseListResponseStructureMatchingLDCS matchingLdcs = new CourseListResponseStructureMatchingLDCS();
                matchingLdcs.LDCS   = BuildLdcsInfoType(ldcsCode.LdcsCodeValue, ldcsCode.LdcsCodeDescription);
                matchingLdcs.Counts = ldcsCode.CourseCount.ToString();

                matchingLdcss.Add(matchingLdcs);
            }

            courseListResponse.MatchingLDCS = matchingLdcss.ToArray();

            // Create CourseStructure collection
            List <CourseStructure> courseStructures = new List <CourseStructure>();

            foreach (Course course in response.Courses)
            {
                // Get Course information
                CourseStructure courseStructure = new CourseStructure();

                courseStructure.Course               = new CourseInfo();
                courseStructure.Course.CourseID      = course.CourseId.ToString();
                courseStructure.Course.CourseSummary = course.CourseSummary;
                courseStructure.Course.CourseTitle   = course.CourseTitle;

                courseStructure.Course.LDCS               = new LDCSOutputType();
                courseStructure.Course.LDCS.CatCode1      = BuildLdcsInfoType(course.LdcsCode1, course.LdcsDesc1);
                courseStructure.Course.LDCS.CatCode2      = BuildLdcsInfoType(course.LdcsCode2, course.LdcsDesc2);
                courseStructure.Course.LDCS.CatCode3      = BuildLdcsInfoType(course.LdcsCode3, course.LdcsDesc3);
                courseStructure.Course.LDCS.CatCode4      = BuildLdcsInfoType(course.LdcsCode4, course.LdcsDesc4);
                courseStructure.Course.LDCS.CatCode5      = BuildLdcsInfoType(course.LdcsCode5, course.LdcsDesc5);
                courseStructure.Course.NoOfOpps           = course.NumberOfOpportunities.ToString();
                courseStructure.Course.QualificationLevel = course.QualificationLevel;
                courseStructure.Course.QualificationType  = course.QualificationType;

                // Get Opportunity information
                List <OpportunityInfo> opportunityInfos = new List <OpportunityInfo>();

                foreach (Opportunity opportunity in course.Opportunities)
                {
                    OpportunityInfo opportunityInfo = new OpportunityInfo();

                    opportunityInfo.AttendanceMode    = opportunity.AttendanceMode;
                    opportunityInfo.AttendancePattern = opportunity.AttendancePattern;
                    opportunityInfo.OpportunityId     = opportunity.OpportunityId;

                    StartDateType startDateType = BuildStartDateType(opportunity);

                    //StartDateType startDateType = new StartDateType();
                    //startDateType.ItemElementName = ItemChoiceType.Date;
                    //startDateType.Item = opportunity.StartDate;

                    // TODO: how do we add these in?  I suspect we need to change the contract.
                    //StartDateType startDateDescType = new StartDateType();
                    //startDateDescType.ItemElementName = ItemChoiceType.DateDesc;
                    //startDateDescType.Item = opportunity.StartDateDescription;

                    opportunityInfo.StartDate = startDateType;
                    opportunityInfo.Duration  = new DurationType();
                    opportunityInfo.Duration.DurationDescription = opportunity.DurationDescription;
                    opportunityInfo.Duration.DurationUnit        = opportunity.DurationUnit;

                    if (opportunity.DurationValue != 0)
                    {
                        opportunityInfo.Duration.DurationValue = opportunity.DurationValue.ToString();
                    }

                    opportunityInfo.EndDate                = opportunity.EndDate;
                    opportunityInfo.StudyMode              = opportunity.StudyMode;
                    opportunityInfo.DFE1619Funded          = opportunity.DfE1619Funded;
                    opportunityInfo.DFE1619FundedSpecified = true;

                    if (opportunity.Venue != null && !string.IsNullOrEmpty(opportunity.Venue.VenueName))
                    {
                        VenueInfo venueInfo = new VenueInfo();
                        if (!string.IsNullOrEmpty(opportunity.Distance))
                        {
                            venueInfo.DistanceSpecified = true;
                            venueInfo.Distance          = float.Parse(opportunity.Distance);
                        }
                        venueInfo.VenueName    = opportunity.Venue.VenueName;
                        venueInfo.VenueAddress =
                            BuildAddressType(opportunity.Venue.AddressLine1, opportunity.Venue.AddressLine2,
                                             opportunity.Venue.Town, opportunity.Venue.County, opportunity.Venue.Postcode, opportunity.Venue.Latitude, opportunity.Venue.Longitude);

                        opportunityInfo.Item = venueInfo;
                    }
                    else
                    {
                        opportunityInfo.Item = opportunity.RegionName;
                    }

                    opportunityInfos.Add(opportunityInfo);
                }

                // pick out the first opportunity (expecting there to be only one looking at the java web service's design).
                // if there is more than one here - then current site cannot deal with it.
                courseStructure.Opportunity = opportunityInfos.ElementAt(0);

                courseStructure.Provider = new ProviderInfo();
                courseStructure.Provider.ProviderName           = course.Provider.ProviderName;
                courseStructure.Provider.TFPlusLoans            = course.Provider.TFPlusLoans;
                courseStructure.Provider.TFPlusLoansSpecified   = true;
                courseStructure.Provider.DFE1619Funded          = course.Provider.DFE1619Funded;
                courseStructure.Provider.DFE1619FundedSpecified = true;

                if (course.Provider.FEChoices_EmployerSatisfaction.HasValue)
                {
                    courseStructure.Provider.FEChoices_EmployerSatisfaction = course.Provider.FEChoices_EmployerSatisfaction.Value;
                }
                courseStructure.Provider.FEChoices_EmployerSatisfactionSpecified = course.Provider.FEChoices_EmployerSatisfaction.HasValue;
                if (course.Provider.FEChoices_LearnerSatisfaction.HasValue)
                {
                    courseStructure.Provider.FEChoices_LearnerSatisfaction = course.Provider.FEChoices_LearnerSatisfaction.Value;
                }
                courseStructure.Provider.FEChoices_LearnerSatisfactionSpecified = course.Provider.FEChoices_LearnerSatisfaction.HasValue;
                if (course.Provider.FEChoices_LearnerDestination.HasValue)
                {
                    courseStructure.Provider.FEChoices_LearnerDestination = course.Provider.FEChoices_LearnerDestination.Value;
                }
                courseStructure.Provider.FEChoices_LearnerDestinationSpecified = course.Provider.FEChoices_LearnerDestination.HasValue;


                courseStructures.Add(courseStructure);
            }

            courseListResponse.CourseDetails = courseStructures.ToArray();

            // Get Result information, i.e. page number etc.
            courseListResponse.ResultInfo = new ResultInfoType();

            int requestRecordsPerPage = 0;

            if (!string.IsNullOrEmpty(request.RecordsPerPage))
            {
                requestRecordsPerPage = Int32.Parse(request.RecordsPerPage);
            }

            int responseRecordsPerPage = (requestRecordsPerPage > 0) ? requestRecordsPerPage : 50;
            int totalRecords           = response.NumberOfRecords;
            int numberOfPages          =
                (totalRecords / responseRecordsPerPage) + ((totalRecords % responseRecordsPerPage == 0) ? 0 : 1);

            int currentPage = 1;

            if (!string.IsNullOrEmpty(request.PageNo))
            {
                currentPage = Int32.Parse(request.PageNo);
            }

            courseListResponse.ResultInfo.NoOfRecords = response.NumberOfRecords.ToString();
            courseListResponse.ResultInfo.PageNo      = (currentPage > 0) ? currentPage.ToString() : "1";
            courseListResponse.ResultInfo.NoOfPages   = numberOfPages.ToString();

            // Get original Request details
            courseListResponse.RequestDetails = request;

            return(courseListResponse);
        }
        /// <summary>
        /// Creates a repeater friendly CourseSearchResult object from the response.
        /// </summary>
        /// <param name="course">The CourseStructure response from the search.</param>
        /// <returns>A populated CourseSearchResult object.</returns>
        private CourseSearchResult CreateResult(CourseStructure course)
        {
            CourseSearchResult result = new CourseSearchResult();

            if (course != null && course.Course != null)
            {
                // COURSE
                result.CourseID      = HttpUtility.HtmlEncode(course.Course.CourseID);
                result.CourseName    = HttpUtility.HtmlEncode(course.Course.CourseTitle);
                result.CourseSummary = HttpUtility.HtmlEncode(course.Course.CourseSummary);

                result.CourseDfEFunded = course.Opportunity.DFE1619Funded;

                result.LDCS1            = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode1.LDCSCode);
                result.LDCS1Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode1.LDCSDesc);
                result.LDCS2            = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode2.LDCSCode);
                result.LDCS2Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode2.LDCSDesc);
                result.LDCS3            = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode3.LDCSCode);
                result.LDCS3Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode3.LDCSDesc);
                result.LDCS4            = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode4.LDCSCode);
                result.LDCS4Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode4.LDCSDesc);
                result.LDCS5            = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode5.LDCSCode);
                result.LDCS5Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode5.LDCSDesc);

                result.NumberOfOpportunities = HttpUtility.HtmlEncode(course.Course.NoOfOpps);

                result.QualificationLevel = HttpUtility.HtmlEncode(course.Course.QualificationLevel);
                result.QualificationType  = HttpUtility.HtmlEncode(course.Course.QualificationType);

                // OPPORTUNITY
                if (course.Opportunity != null)
                {
                    result.OpportunityID     = HttpUtility.HtmlEncode(course.Opportunity.OpportunityId);
                    result.AttendanceMode    = HttpUtility.HtmlEncode(course.Opportunity.AttendanceMode);
                    result.AttendancePattern = HttpUtility.HtmlEncode(course.Opportunity.AttendancePattern);

                    if (course.Opportunity.Duration != null)
                    {
                        result.DurationDescription = HttpUtility.HtmlEncode(course.Opportunity.Duration.DurationDescription);
                        result.DurationUnit        = HttpUtility.HtmlEncode(course.Opportunity.Duration.DurationUnit);
                        result.DurationValue       = HttpUtility.HtmlEncode(course.Opportunity.Duration.DurationValue);
                    }

                    if (course.Opportunity.Item != null)
                    {
                        // could be VenueInfo or a Region name
                        if (course.Opportunity.Item.GetType() == typeof(VenueInfo))
                        {
                            VenueInfo venueInfo = course.Opportunity.Item as VenueInfo;
                            if (venueInfo != null)
                            {
                                result.Venue    = venueInfo.VenueName;
                                result.Distance = venueInfo.Distance.ToString();
                                if (venueInfo.VenueAddress != null)
                                {
                                    result.AddressLine1 = venueInfo.VenueAddress.Address_line_1;
                                    result.AddressLine2 = venueInfo.VenueAddress.Address_line_2;
                                    result.Town         = venueInfo.VenueAddress.Town;
                                    result.County       = venueInfo.VenueAddress.County;
                                    result.Postcode     = venueInfo.VenueAddress.PostCode;
                                    result.Latitude     = venueInfo.VenueAddress.Latitude;
                                    result.Longitude    = venueInfo.VenueAddress.Longitude;
                                }
                            }
                        }
                        else if (course.Opportunity.Item is String)
                        {
                            result.RegionName = course.Opportunity.Item.ToString();
                        }
                    }

                    if (course.Opportunity.StartDate.ItemElementName.ToString() == "Date")
                    {
                        if (course.Opportunity.StartDate.Item != null)
                        {
                            result.StartDate = course.Opportunity.StartDate.Item;
                        }
                    }
                    else
                    {
                        result.StartDateDescription = course.Opportunity.StartDate.Item;
                    }

                    result.StudyMode = HttpUtility.HtmlEncode(course.Opportunity.StudyMode);
                }

                result.OpportunityID = HttpUtility.HtmlEncode(course.Opportunity.OpportunityId);

                // PROVIDER
                result.ProviderName                   = HttpUtility.HtmlEncode(course.Provider.ProviderName);
                result.TFPlusLoans                    = course.Provider.TFPlusLoans;
                result.ProviderDfEFunded              = course.Provider.DFE1619Funded;
                result.FEChoices_LearnerDestination   = course.Provider.FEChoices_LearnerDestinationSpecified ? course.Provider.FEChoices_LearnerDestination : (Double?)null;
                result.FEChoices_LearnerSatisfaction  = course.Provider.FEChoices_LearnerSatisfactionSpecified ? course.Provider.FEChoices_LearnerSatisfaction : (Double?)null;
                result.FEChoices_EmployerSatisfaction = course.Provider.FEChoices_EmployerSatisfactionSpecified ? course.Provider.FEChoices_EmployerSatisfaction : (Double?)null;
            }

            return(result);
        }
Exemplo n.º 8
0
 public void Commit(TopicWrap wrap, CourseStructure structure)
 {
     wrap.Topic.Items.Clear();
     foreach (var e in wrap.Items)
     {
         if (e is TopicWrap)
         {
             var tw = e as TopicWrap;
             Commit(tw,structure);
             wrap.Topic.Items.Add(tw.Topic);
             continue;
         }
         if (e is VideoWrap)
         {
             var vw = e as VideoWrap;
             var relation = new VideoToTopicRelation();
             relation.TopicGuid = wrap.Topic.Guid;
             relation.NumberInTopic = wrap.Items.IndexOf(vw);
             relation.VideoGuid = vw.Video.Guid;
             structure.VideoToTopicRelations.Add(relation);
         }
     }
 }
Exemplo n.º 9
0
 public CourseStructure Commit()
 {
     var result = new CourseStructure();
     Commit(Root[0], result);
     result.RootTopic = Root[0].Topic;
     return result;
 }