Пример #1
0
        public async Task <Guid> Create(Models.CompetencesPJ compPJ)
        {
            try
            {
                var context = CreateContext();
                var created = new Data.CompetencesPJ
                {
                    PJId         = compPJ.PJId,
                    CompetenceId = compPJ.CompetenceId,
                    CompVal      = compPJ.CompVal,
                    Id           = compPJ.Id,
                };
                var enr = await context
                          ._CompetencesPJ
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(compPJ.Id);
            }
        }
Пример #2
0
        public async Task Delete(Models.CompetencesPJ compPJ)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._CompetencesPJ.FindAsync(compPJ.Id);

                if (toDelete != null)
                {
                    context._CompetencesPJ.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #3
0
        public async Task Update(Models.CompetencesPJ compPJ)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._CompetencesPJ.FindAsync(compPJ.Id);

                if (toUpdate != null)
                {
                    toUpdate.PJId         = compPJ.PJId;
                    toUpdate.CompetenceId = compPJ.CompetenceId;
                    toUpdate.CompVal      = compPJ.CompVal;
                    toUpdate.Id           = compPJ.Id;

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