コード例 #1
0
        private async Task UploadIntoFileDbAsync(File savedEntity, UploadDocumentView model)
        {
            var fileDb = new FileDB()
            {
                Id    = savedEntity.IdGuid,
                Bytes = StreamToBytes(model.File.OpenReadStream())
            };

            await _fileDbContext.FileDB.AddAsync(fileDb);

            await _fileDbContext.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <IFileResponse> UploadDocumentAsync(UploadDocumentView model)
        {
            try
            {
                var savedEntity = await SaveFileAsync(model);

                var profile = await _appDbContext.Profiles.FirstOrDefaultAsync(k => k.Id == model.UserId);

                if (profile == null)
                {
                    return(new FileResponse(ClientMessageConstant.ProfileNotExist, HttpStatusCode.NotFound));
                }
                switch (model.DocumentType)
                {
                case DocumentType.Passport:
                    profile.PassportFileId = savedEntity.Id;
                    break;

                case DocumentType.Education:
                    profile.LastEducationCertificateFileId = savedEntity.Id;
                    break;

                case DocumentType.CV:
                    profile.CvfileId = savedEntity.Id;
                    break;

                case DocumentType.Emirates:
                    profile.UaeidfileId = savedEntity.Id;
                    break;

                case DocumentType.FamilyBook:
                    profile.FamilyBookFileId = savedEntity.Id;
                    break;
                }

                await UploadIntoFileDbAsync(savedEntity, model);

                await _appDbContext.SaveChangesAsync();

                return(new FileResponse(true, "Success", HttpStatusCode.Accepted));
            }
            catch (Exception e)
            {
                return(new FileResponse(e));
            }
        }
コード例 #3
0
        private async Task <File> SaveFileAsync(UploadDocumentView model)
        {
            var userInfo = await _appDbContext.UserInfos.Include(k => k.User).FirstOrDefaultAsync(k => k.Id == model.UserId);

            var data = new File()
            {
                IdGuid       = Guid.NewGuid(),
                SizeMb       = GetFileSize(model.File.Length),
                Name         = model.File.FileName,
                ProviderName = "SqlProvider",
                ExtraParams  = model.ExtraParams,
                Created      = DateTime.UtcNow,
                MimeType     = model.File.ContentType,
                Modified     = DateTime.UtcNow,
                CreatedBy    = userInfo.Email,
                ModifiedBy   = userInfo.Email
            };

            var savedEntity = (await _appDbContext.Files.AddAsync(data)).Entity;
            await _appDbContext.SaveChangesAsync();

            return(savedEntity);
        }
コード例 #4
0
        public async Task <IActionResult> UploadDocumentAsync([FromForm] UploadDocumentView viewModel)
        {
            var model = await _fileService.UploadDocumentAsync(viewModel);

            return(Ok(model));
        }