コード例 #1
0
        public async Task <Guid> Create(Models.RelationsPJ_BG relaBG)
        {
            try
            {
                var context = CreateContext();
                var created = new Data.RelationsPJ_BG
                {
                    Id         = relaBG.Id,
                    RelationId = relaBG.RelationId,
                    Version    = relaBG.Version,
                    TitreBg    = relaBG.TitreBg,
                    BG_Corps   = relaBG.BG_Corps,
                };
                var enr = await context
                          ._RelationsPJ_BG
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(relaBG.Id);
            }
        }
コード例 #2
0
        public async Task Delete(Models.RelationsPJ_BG relaBG)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._RelationsPJ_BG.FindAsync(relaBG.Id);

                if (toDelete != null)
                {
                    context._RelationsPJ_BG.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #3
0
        public async Task Update(Models.RelationsPJ_BG relaBG)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._RelationsPJ_BG.FindAsync(relaBG.Id);

                if (toUpdate != null)
                {
                    toUpdate.Id         = relaBG.Id;
                    toUpdate.RelationId = relaBG.RelationId;
                    toUpdate.Version    = relaBG.Version;
                    toUpdate.TitreBg    = relaBG.TitreBg;
                    toUpdate.BG_Corps   = relaBG.BG_Corps;
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }