public ActionResult Create([FromBody] CourseSolution review)
        {
            Guid userId = Guid.Parse(User.Identity.Name);

            _solutionService.Create(review, userId);
            return(Ok());
        }
Example #2
0
        public void CreateSolution()
        {
            var token  = InstanceFactory.AuthorizedUserId();
            var course = InstanceFactory.Course();

            course = _courseService.Create(course, token);
            var courseTask = InstanceFactory.CourseTask(token, course.Id);

            courseTask = _courseTaskService.Create(courseTask, token);

            var solution        = InstanceFactory.Solution(token, courseTask.Id);
            var createdSolution = _solutionService.Create(solution, token);

            Assert.IsNotNull(createdSolution);
            Assert.AreEqual(token, createdSolution.AuthorId);
            Assert.AreEqual(courseTask.Id, createdSolution.CourseTaskId);
        }
Example #3
0
        public void CreateReview()
        {
            var token  = InstanceFactory.AuthorizedUserId();
            var course = InstanceFactory.Course();

            course = _courseService.Create(course, token);
            var courseTask = InstanceFactory.CourseTask(token, course.Id);

            courseTask = _courseTaskService.Create(courseTask, token);
            var solution = InstanceFactory.Solution(token, courseTask.Id);

            solution = _solutionService.Create(solution, token);

            var review        = InstanceFactory.Review(token, solution.Id, courseTask);
            var createdReview = _reviewService.Create(review, token);

            Assert.IsNotNull(createdReview);
        }
Example #4
0
        /// <summary>
        /// 导入解决方案
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <bool> ImportAsync(IFormFile file)
        {
            var dir      = _webHelper.MapPath("~/solution/import/" + DateTime.Now.ToString("yyMMddhhmmss"));
            var d        = Directory.CreateDirectory(dir);
            var filePath = dir + "/" + file.FileName;
            await file.SaveAs(filePath, _settingFinder, _webHelper).ConfigureAwait(false);

            IOHelper.UnZip(filePath);
            //解决方案信息
            var solution = new Domain.Solution();

            solution = solution.DeserializeFromXMLFile(dir + "/solution.xml");
            var existSolution = _solutionService.FindById(solution.SolutionId);

            if (existSolution != null)
            {
                existSolution.Name        = solution.Name;
                existSolution.Description = solution.Description;
                existSolution.Version     = solution.Version;
                existSolution.ModifiedBy  = _currentUser.SystemUserId;
                existSolution.ModifiedOn  = DateTime.Now;
                _solutionService.Update(existSolution);
            }
            else
            {
                solution.CreatedBy   = _currentUser.SystemUserId;
                solution.InstalledOn = DateTime.Now;
                solution.PublisherId = _currentUser.SystemUserId;
                _solutionService.Create(solution);
            }
            //自定义内容
            XDocument doc = XDocument.Load(dir + "/customizations.xml");
            IEnumerable <XElement> elements = from e in doc.Element("ImportExportXml").Elements()
                                              select e;

            foreach (var node in elements)
            {
                var importerTypeName = ImporterTypes[node.Name.ToString()];
                if (importerTypeName.IsNotEmpty())
                {
                    var importerType = ImporterNodeTypeMapper.Get(node.Name.ToString());//Type.GetType(importerTypeName);
                    if (importerType != null)
                    {
                        var componentArg    = importerType.GetInterface(typeof(ISolutionComponentImporter <>).Name).GenericTypeArguments[0];
                        var importerService = _serviceResolver.Get(typeof(ISolutionComponentImporter <>).MakeGenericType(componentArg));
                        var listType        = typeof(List <>).MakeGenericType(componentArg);
                        var listObj         = Activator.CreateInstance(listType);
                        foreach (var item in node.Elements())
                        {
                            var component = Activator.CreateInstance(componentArg);
                            component = Serializer.FromXml(componentArg, item.ToString());
                            listType.GetMethod("Add").Invoke(listObj, new[] { component });
                        }
                        //invoke import method
                        var importMethod = importerType.GetMethod("Import");
                        var importResult = importMethod.Invoke(importerService, new[] { solution.SolutionId, listObj });
                    }
                }
            }
            //delete files
            Directory.Delete(dir, true);

            return(true);
        }