Beispiel #1
0
        public void Validate()
        {
            var validator        = new CourseValidator();
            var validationResult = validator.Validate(this);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors.Select(i => i.ErrorCode));
            }
        }
        public void CourseCreate()
        {
            var courseVM = courseHelper.CourseFullData();

            if (validator.Validate(courseVM).IsValid&& courseVM.Skills.Count >= 1 && courseVM.Materials.Count >= 1)
            {
                var mappedCourse = mapper.Map <CourseVM, Course>(courseVM);
                courseService.AddCourse(mappedCourse);

                courseVM.Id = mappedCourse.Id;

                Dye.Succsess();
                Console.WriteLine("You have successfully created course");
                Console.ResetColor();
            }
            else
            {
                Dye.Fail();
                Console.WriteLine(validator.Validate(courseVM));
                Console.WriteLine(new Exception("Course is not added, try again."));
                Console.ResetColor();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Save all changes of current course to folder that represents is
        /// </summary>
        public static bool Save()
        {
            FFDebug.EnterMethod(Cattegory.Course, State.ToString());
            State |= CourseStates.Saving;

#if CHECKERS
            if (__Manifest == null)
            {
                throw new FireFlyException("Course is not assigned");
            }
            if (__Manifest.organizations.Organizations.Count == 0)
            {
                throw new FireFlyException("No organization assigned");
            }
#endif
            if (CourseSaving != null)
            {
                CourseSaving();
            }
            HtmlPageBase.StorePages();

            State &= ~CourseStates.Saving;


            var cv = new CourseValidator();
            if (!cv.Validate())
            {
                ErrorDialog.ShowError("THIS COURSE IS INVALID!!! It cannot be played. Errors:" + Environment.NewLine + cv.GetErrorMessages());
                State &= ~CourseStates.Modified;
                return(false);
            }

            using (var f = new FileStream(MapPath(MANIFEST_FILE_NAME), FileMode.Create))
            {
                ManifestType.Serializer.Serialize(f, __Manifest, ManifestNamespaces.SerializerNamespaces);
            }
            Answers.SaveToFile(MapPath(ANSWERS_FILE_NAME));
            State &= ~CourseStates.Modified;

            if (CourseSaved != null)
            {
                CourseSaved();
            }

            FFDebug.LeaveMethod(Cattegory.Course, MethodBase.GetCurrentMethod());

            return(true);
        }
        public static async Task Run(
            string input,          // Work around https://github.com/Azure/azure-functions-vs-build-sdk/issues/168
            ILogger log,
            [Inject] IConfigurationRoot configuration,
            [Inject] ICourseCollectionService courseCollectionService,
            [Inject] ICosmosDbHelper cosmosDbHelper,
            [Inject] IBlobStorageHelper blobhelper,
            [Inject] IUkrlpApiService ukrlpApiService
            )
        {
            const string apprenticeshipAppName = "Validate.Course";

            var apprenticeshipValidationFileName = $"{apprenticeshipAppName}-{DateTime.Now.ToString("dd-MM-yy HHmm")}";
            var blobContainer = blobhelper.GetBlobContainer(configuration["BlobStorageSettings:Container"]);
            var validator     = new CourseValidator();

            List <CourseValidationResult> validationEResult = new List <CourseValidationResult>();

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var resultData = await courseCollectionService.GetAllCoursesAsync();

            foreach (var item in resultData)
            {
                //item.ContactEmail = "testing";
                //item.Url = "testing";
                //item.ContactWebsite = "testing";
                //item.ContactTelephone = "101101abc";
                //item.ApprenticeshipTitle = item.ApprenticeshipTitle + " @";

                var validationResult = validator.Validate(item);

                if (!validationResult.IsValid)
                {
                    foreach (var error in validationResult.Errors)
                    {
                        validationEResult.Add(new CourseValidationResult()
                        {
                            CourseId      = item.CourseId,
                            ProviderUkprn = item.ProviderUKPRN,
                            FieldName     = error.PropertyName,
                            ErrorMessage  = error.ErrorMessage
                        });
                    }
                }
            }

            var resultsObjBytes = GetResultAsByteArray(validationEResult);

            await WriteResultsToBlobStorage(resultsObjBytes);

            stopWatch.Stop();

            byte[] GetResultAsByteArray(IList <CourseValidationResult> message)
            {
                using (var memoryStream = new System.IO.MemoryStream())
                {
                    using (var streamWriter = new System.IO.StreamWriter(memoryStream))
                        using (var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture))
                        {
                            csvWriter.WriteRecords <CourseValidationResult>(message);
                        }
                    return(memoryStream.ToArray());
                }
            }

            async Task WriteResultsToBlobStorage(byte[] data)
            {
                await blobhelper.UploadFile(blobContainer, apprenticeshipValidationFileName, data);
            }
        }