Exemple #1
0
        public async Task AddEntityAsync(EntityAdd model)
        {
            if (string.IsNullOrWhiteSpace(model.EntityTypeName))
            {
                throw new ArgumentException("Entity type is not specified");
            }

            var entityTypeName = model.EntityTypeName.Trim().ToLowerInvariant();
            var json           = model.Data;

            var jsonValueKind = json.ValueKind;

            if (jsonValueKind != JsonValueKind.Object &&
                jsonValueKind != JsonValueKind.Array)
            {
                throw new ArgumentException("Invalid json");
            }

            await ProcessEntitiesInternalAsync(entityTypeName, json);

            await dbContext.SaveChangesAsync();
        }
Exemple #2
0
        public async Task <IActionResult> Post(int patientId, [FromBody] ComplementEditModel[] model)
        {
            var complements = await _genericService.Find <Complement>(
                x => model.Any(y => y.Id == x.Id),
                includeProperties : "ComplementaryMethods,LaboratoryInstances");

            using (var dbTransacton = _dbContext.Database.BeginTransaction())
            {
                foreach (var comp in complements)
                {
                    comp.ComplementaryMethods.Clear();
                    comp.LaboratoryInstances.Clear();

                    // adding complementary method
                    var compMethods = model.First(x => x.Id == comp.Id)
                                      .ComplementaryMethods
                                      .Select(x => new ComplementaryMethodInstance(x.ComplementaryMethodId, x.Value))
                                      .ToArray();

                    comp.ComplementaryMethods.AddRange(compMethods);


                    // adding labs
                    var labs = model.First(x => x.Id == comp.Id)
                               .Laboratories
                               .Select(x => new LaboratoryInstance(x.LaboratoryId, x.Value))
                               .ToArray();

                    comp.LaboratoryInstances.AddRange(labs);
                }
                await _dbContext.SaveChangesAsync();

                dbTransacton.Commit();
            }
            return(Ok());
        }
Exemple #3
0
 public Task <int> CommitAsync()
 {
     return(_ctx.SaveChangesAsync());
 }
 public async Task SaveAsync()
 {
     await _db.SaveChangesAsync();
 }