public async Task <IActionResult> Create([FromForm] DocumentUpLoad documentUpload) { // Find User if (documentUpload != null) { var document = documentUpload.Document; if (document != null) { var user = _context.Users.Where(x => x.Id == documentUpload.UserId).Include(user => user.Profile).ThenInclude(profile => profile.Documents).FirstOrDefault(); if (user != null) { using (var binaryReader = new BinaryReader(document.OpenReadStream())) { var imageData = binaryReader.ReadBytes((int)document.Length); var documentData = new Documents(); documentData.Document = imageData; user.Profile.Documents.Add(documentData); _context.SaveChanges(); } } } } return(Ok()); }
public static void Initialize(ApiExamplesContext context) { if (!context.Users.Any()) { var user = new User(); var userProfile = new OrganizationalProfile(); userProfile.Department = "Co Lab"; userProfile.Name = "Allan"; userProfile.Surname = "Pead"; user.Password = "******"; user.UserName = "******"; user.Profile = userProfile; context.Users.Add(user); context.SaveChanges(); } }