示例#1
0
        public async Task <Guid> StartNewFormAsync(FormAccessLevel accessLevel, string key, PreFillLookupCriteria criteria)
        {
            var form = await _db.Forms.FirstOrDefaultAsync(f => f.AccessLevel == accessLevel && f.Key == key);

            if (form is null)
            {
                throw new Exception("No matching form");
            }

            var entry = new FormEntry
            {
                FormKey         = form.Key,
                PrefillCriteria = criteria,
                Status          = FormStatus.Open,
            };

            var preFillProcessors = await _db.PreFillProcessors.Where(p => p.FormKey == key).ToArrayAsync();

            foreach (var processor in preFillProcessors)
            {
                await _preFillProcessor.ProcessFormAsync(processor, entry);
            }

            if (form.Key == "ocif")
            {
                //var ocif = new FormOCIF
                //{
                //    Id = entry.Id,
                //    Data = entry.Data,
                //};

                //await _db.AddAsync(ocif);

                var ocif = new OCIF
                {
                    ID       = entry.Id,
                    JSONData = entry.Data
                };

                await _uiPathDb.AddAsync(ocif);

                await _uiPathDb.SaveChangesAsync();
            }

            await _db.AddAsync(entry);

            await _db.SaveChangesAsync();

            return(entry.Id);
        }
示例#2
0
 public virtual async Task <IActionResult> StartNewForm(string key, [FromBody] PreFillLookupCriteria criteria)
 {
     return(Ok(new { Id = await _formService.StartNewFormAsync(_accessLevel, key, criteria), Key = key, AccessLevel = _accessLevel }));
 }