public async Task <ActionResult> AddReportsToParent([FromForm] ReportStudentGroup[] reports, int centerid, int groupid, IFormFile NextLecture, IFormFile Homework) { string NextLectureName = ""; string HomeworkName = ""; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (reports == null) { return(NotFound()); } if (NextLecture != null && Homework != null) { if (NextLecture.Length != 0 || Homework.Length != 0) { return(NotFound()); } if (NextLecture.Length > _photoSetting.MaxBytes || Homework.Length > _photoSetting.MaxBytes) { return(BadRequest("Max file size exceeded")); } var uploadsFolderPath = Path.Combine(_host.WebRootPath, "ReportsFiles"); if (!Directory.Exists(uploadsFolderPath)) { Directory.CreateDirectory(uploadsFolderPath); } NextLectureName = Guid.NewGuid().ToString() + Path.GetExtension(NextLecture.FileName); var NextLecturePath = Path.Combine(uploadsFolderPath, NextLectureName); // filepath HomeworkName = Guid.NewGuid().ToString() + Path.GetExtension(Homework.FileName); var HomeworkPath = Path.Combine(uploadsFolderPath, HomeworkName); // filepath using (var stream = new FileStream(NextLecturePath, FileMode.Create)) { await NextLecture.CopyToAsync(stream); // picture saved to the path (folder) } using (var stream = new FileStream(HomeworkPath, FileMode.Create)) { await Homework.CopyToAsync(stream); // picture saved to the path (folder) } var group = await _eductionalCenterGroupRepository.GetEductionalCenterGroupById(groupid); if (group == null || centerid == 0 || group.EductionalCenterId != centerid) { return(Content("not found , please Check!...")); } } int reportId = await _reportSupRepository.AddReport(NextLectureName, HomeworkName); await _reportRepository.AddAllReportsToParent(reports, reportId); return(Created("TeacherTable", reports)); }