示例#1
0
        public async Task <Guid> Create(Models.PNJScene pnjscn)
        {
            try
            {
                var context = CreateContext();
                var created = new Data.PNJScene
                {
                    PNJId   = pnjscn.PNJId,
                    SceneId = pnjscn.SceneId,
                    DescriptionRoleScene = pnjscn.DescriptionRoleScene,
                    Remarques            = pnjscn.Remarques,
                    Id = pnjscn.Id,
                };
                var enr = await context
                          ._PNJScene
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(pnjscn.Id);
            }
        }
示例#2
0
        public async Task Delete(Models.PNJScene pnjscn)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._PNJScene.FindAsync(pnjscn.Id);

                if (toDelete != null)
                {
                    context._PNJScene.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#3
0
        public async Task Update(Models.PNJScene pnjscn)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._PNJScene.FindAsync(pnjscn.Id);

                if (toUpdate != null)
                {
                    toUpdate.PNJId   = pnjscn.PNJId;
                    toUpdate.SceneId = pnjscn.SceneId;
                    toUpdate.DescriptionRoleScene = pnjscn.DescriptionRoleScene;
                    toUpdate.Remarques            = pnjscn.Remarques;
                    toUpdate.Id = pnjscn.Id;

                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }