Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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();
            }
        }