예제 #1
0
 public async Task <SectionWithLoginUsersResult> GetByLoginUserAsync(string SessionKey, int CompanyId, int LoginUserId)
 {
     return(await authorizationProcessor.DoAuthorizeAsync(SessionKey, async token =>
     {
         var result = (await sectionWithLoginUserProcessor.GetAsync(new SectionWithLoginUserSearch {
             CompanyId = CompanyId,
             LoginUserId = LoginUserId,
         }, token)).ToList();
         return new SectionWithLoginUsersResult
         {
             ProcessResult = new ProcessResult {
                 Result = true
             },
             SectionWithLoginUsers = result,
         };
     }, logger));
 }
        /// <summary>インポート処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportResult> ImportAsync(MasterImportSource source, CancellationToken token = default(CancellationToken))
        {
            var mode     = (ImportMethod)source.ImportMethod;
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = companyProcessor.GetAsync(new CompanySearch {
                Id = source.CompanyId,
            }, token);
            var loginUsersTask = loginUserProcessor.GetAsync(new LoginUserSearch {
                CompanyId = source.CompanyId,
            }, token);
            var appConTask  = applicationControlProcessor.GetAsync(source.CompanyId, token);
            var sectionTask = sectionProcessor.GetAsync(new SectionSearch {
                CompanyId = source.CompanyId,
            }, token);

            await Task.WhenAll(companyTask, loginUsersTask, appConTask, sectionTask);

            var company             = companyTask.Result.First();
            var loginUserDictionary = loginUsersTask.Result.ToDictionary(x => x.Code);
            var loginUser           = loginUsersTask.Result.First(x => x.Id == source.LoginUserId);
            var appCon            = appConTask.Result;
            var sectionDictionary = sectionTask.Result.ToDictionary(x => x.Code);

            var definition = new SectionWithLoginUserFileDefinition(new DataExpression(appCon));
            var parser     = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

            definition.SectionCodeField.GetModelsByCode   = codes => sectionDictionary;
            definition.LoginUserCodeField.GetModelsByCode = codes => loginUserDictionary;

            var importer = definition.CreateImporter(x => new { x.SectionId, x.LoginUserId }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.LoadAsync = () => sectionWithLoginUserProcessor.GetAsync(new SectionWithLoginUserSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => sectionWithLoginUserProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

            var result = await importer.ImportAsync(csv, mode, token, null);

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
예제 #3
0
 public async Task <ActionResult <IEnumerable <SectionWithLoginUser> > > GetItems(SectionWithLoginUserSearch option, CancellationToken token)
 => (await sectionWithLoginUserProcessor.GetAsync(option, token)).ToArray();