示例#1
0
        public async Task <IActionResult> PutTraining([FromRoute] int id, [FromBody] Training training)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != training.Id)
            {
                return(BadRequest());
            }

            _context.Entry(training).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TrainingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task AddTraining(Training training)
        {
            int trainingId = 101;

            if (context.Trainings.Count() > 0)
            {
                trainingId = context.Trainings.Max(t => t.TrainingId) + 1;
            }

            training.TrainingId = trainingId;

            context.Trainings.Add(training);

            await context.SaveChangesAsync();
        }
        public async Task CreateTrainingAsync(NewTrainingModel trainingModel)
        {
            _dbContext.Add <Training>(new Training()
            {
                EndDate     = trainingModel.EndDate,
                StartDate   = trainingModel.StartDate,
                Name        = trainingModel.Name,
                CreatedDate = DateTime.Now
            });

            await _dbContext.SaveChangesAsync();
        }
示例#4
0
        public async Task <int> SaveChangesAsync()
        {
            try
            {
                var result = await Context.SaveChangesAsync();

                return(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLineIf(!string.IsNullOrEmpty(ex.Message), ex.ToString());
                throw ex;
            }
        }
示例#5
0
 public async static Task AddToError(Errors ThisError)
 {
     TrainingDbContext db = new TrainingDbContext();
     //  db.Errors.Add(ThisError);
     await db.SaveChangesAsync().ConfigureAwait(false);
 }