/// <summary> /// Basic file receiver for .NET Core /// </summary> /// <param name="id">SchoolBus Owner Id</param> /// <param name="files">Files to add to attachments</param> /// <returns></returns> public IActionResult SchoolbusownersIdAttachmentsPostAsync(int id, IList <IFormFile> files) { // validate the bus id bool exists = _context.SchoolBusOwners.Any(a => a.Id == id); if (exists) { SchoolBusOwner schoolBusOwner = _context.SchoolBusOwners .Include(x => x.Attachments) .Include(x => x.Contacts) .Include(x => x.District.Region) .Include(x => x.History) .Include(x => x.Notes) .Include(x => x.PrimaryContact) .First(a => a.Id == id); AddFilesToAttachments(schoolBusOwner.Attachments, files); _context.SchoolBusOwners.Update(schoolBusOwner); _context.SaveChanges(); List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(schoolBusOwner.Attachments); return(new ObjectResult(result)); } else { // record not found return(new StatusCodeResult(404)); } }
/// <summary> /// Basic file receiver for .NET Core /// </summary> /// <param name="id">Owner Id</param> /// <param name="files">Files to add to attachments</param> /// <returns></returns> public IActionResult OwnerIdAttachmentsPostAsync(int id, IList <IFormFile> files) { // validate the bus id bool exists = _context.Owners.Any(a => a.Id == id); if (exists) { Owner owner = _context.Owners .Include(x => x.Attachments) .First(a => a.Id == id); AddFilesToAttachments(owner.Attachments, files); _context.Owners.Update(owner); _context.SaveChanges(); List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(owner.Attachments); return(new ObjectResult(result)); } else { // record not found return(new StatusCodeResult(404)); } }
/// <summary> /// Basic file receiver for .NET Core /// </summary> /// <param name="id">Owner Id</param> /// <param name="files">Files to add to attachments</param> /// <returns></returns> public IActionResult OwnerIdAttachmentsPostAsync(int id, IList <IFormFile> files) { // validate the bus id bool exists = _context.Owners.Any(a => a.Id == id); if (exists) { Owner owner = _context.Owners .Include(x => x.Attachments) .First(a => a.Id == id); foreach (var file in files) { if (file.Length > 0) { Attachment attachment = new Attachment(); // strip out extra info in the file name if (!string.IsNullOrEmpty(file.FileName)) { attachment.FileName = Path.GetFileName(file.FileName); } // allocate storage for the file and create a memory stream attachment.FileContents = new byte[file.Length]; using (MemoryStream fileStream = new MemoryStream(attachment.FileContents)) { file.CopyTo(fileStream); } attachment.Type = GetType(attachment.FileName); attachment.MimeType = GetMimeType(attachment.Type); owner.Attachments.Add(attachment); } } _context.SaveChanges(); List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(owner.Attachments); return(new ObjectResult(result)); } // record not found return(new StatusCodeResult(404)); }
/// <summary> /// Get attachments associated with a project /// </summary> /// <remarks>Returns attachments for a particular Project</remarks> /// <param name="id">id of Project to fetch attachments for</param> /// <response code="200">OK</response> /// <response code="404">Project not found</response> public virtual IActionResult ProjectsIdAttachmentsGetAsync(int id) { bool exists = _context.Projects.Any(a => a.Id == id); if (exists) { Project project = _context.Projects .Include(x => x.Attachments) .First(a => a.Id == id); var result = MappingExtensions.GetAttachmentListAsViewModel(project.Attachments); return(new ObjectResult(result)); } // record not found return(new StatusCodeResult(404)); }
/// <summary> /// /// </summary> /// <remarks>Returns attachments for a particular SchoolBus</remarks> /// <param name="id">id of SchoolBus to fetch attachments for</param> /// <response code="200">OK</response> /// <response code="404">SchoolBus not found</response> public virtual IActionResult SchoolbusesIdAttachmentsGetAsync(int id) { bool exists = _context.SchoolBuss.Any(a => a.Id == id); if (exists) { SchoolBus schoolBus = _context.SchoolBuss .Include(x => x.Attachments) .First(a => a.Id == id); var result = MappingExtensions.GetAttachmentListAsViewModel(schoolBus.Attachments); return(new ObjectResult(result)); } else { // record not found return(new StatusCodeResult(404)); } }
/// <summary> /// Get attachments associated with a project /// </summary> /// <remarks>Returns attachments for a particular Project</remarks> /// <param name="id">id of Project to fetch attachments for</param> /// <response code="200">OK</response> /// <response code="404">Project not found</response> public virtual IActionResult ProjectsIdAttachmentsGetAsync(int id) { bool exists = _context.Projects.Any(a => a.Id == id); if (exists) { Project project = _context.Projects .Include(x => x.Attachments) .First(a => a.Id == id); List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(project.Attachments); return(new ObjectResult(new HetsResponse(result))); } // record not found return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); }