public async Task<IActionResult> Create([FromForm]Tutorial tutorial)
        {
            if (ModelState.IsValid)
            {
                IFormFile file = Request.Form.Files["UploadedFile"];
                var name = Request.Form["UploadedFileName"];
                var parentid = Request.Form["UploadedFileParentID"];
                var path = Request.Form["UploadedFilePath"];
                var projectid = Request.Form["UploadedProjectID"];
                var taskid = Request.Form["UploadedTaskID"];
                if (file != null)
                {
                    if (!Directory.Exists(_environment.WebRootPath + "\\video\\"))
                    {
                        Directory.CreateDirectory(_environment.WebRootPath + "\\video\\");
                    }
                    using (FileStream fileStream = System.IO.File.Create(_environment.WebRootPath + "\\video\\" + file.FileName))
                    {
                        file.CopyTo(fileStream);
                        fileStream.Flush();

                        var item = new Tutorial();
                        item.Level = 1;
                        item.Name = name.ToSafetyString();
                        item.ParentID = parentid.ToInt();
                        item.URL = $"{Request.Scheme}://{Request.Host.Value}/video/{file.FileName}";
                        item.Path = path.ToSafetyString();
                        if (projectid.ToInt() > 0)
                            item.ProjectID = projectid.ToInt();
                        if (taskid.ToInt() > 0)
                            item.TaskID = taskid.ToInt();
                        await _tutorialService.Create(item);
                    }
                }
                else
                {
                    var item = tutorial;
                    item.Level = 1;
                    item.Name = name.ToSafetyString();
                    item.Path = path.ToSafetyString();
                    if (projectid.ToInt() > 0)
                    item.ProjectID = projectid.ToInt();

                    item.ParentID = parentid.ToInt();
                    if (taskid.ToInt() > 0)
                        item.TaskID = taskid.ToInt();
                    await _tutorialService.Create(item);
                }
                //_context.Add(entity);
                //await _context.SaveChangesAsync();
                return Ok(tutorial);

            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }
            return Ok(tutorial);

        }
Exemplo n.º 2
0
 public OkResult Create([FromBody] CreateTutorialModel res)
 {
     _tutorialService.Create(res.Title, res.Sources.Select(s => new TutorialSource
     {
         Content = s.Content,
         Type    = s.Type
     }), res.ExerciceId);
     return(Ok());
 }