Ejemplo n.º 1
0
        public async Task Update(Models.RelationsPJ relaPJ)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._RelationsPJ.FindAsync(relaPJ.Id);

                int niv;
                niv = relaPJ.NivRel switch
                {
                    NivRelation.LienFaible => niv = 0,
                    NivRelation.LienFort => niv   = 1,
                    NivRelation.LienIntime => niv = 2,
                    _ => niv = 0,
                };
                if (toUpdate != null)
                {
                    toUpdate.PJ1Id       = relaPJ.PJ1Id;
                    toUpdate.PJ2Id       = relaPJ.PJ2Id;
                    toUpdate.Id          = relaPJ.Id;
                    toUpdate.NivRelation = niv;

                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task <Guid> Create(Models.RelationsPJ relaPJ)
        {
            try
            {
                var context = CreateContext();
                int niv;
                niv = relaPJ.NivRel switch
                {
                    NivRelation.LienFaible => niv = 0,
                    NivRelation.LienFort => niv   = 1,
                    NivRelation.LienIntime => niv = 2,
                    _ => niv = 0,
                };
                var created = new Data.RelationsPJ
                {
                    PJ1Id       = relaPJ.PJ1Id,
                    PJ2Id       = relaPJ.PJ2Id,
                    Id          = relaPJ.Id,
                    NivRelation = niv,
                };
                var enr = await context
                          ._RelationsPJ
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(relaPJ.Id);
            }
        }
Ejemplo n.º 3
0
        public async Task Delete(Models.RelationsPJ relaPJ)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._RelationsPJ.FindAsync(relaPJ.Id);

                if (toDelete != null)
                {
                    context._RelationsPJ.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }