Esempio n. 1
0
        public Student CreateStudent(Student student)
        {
            var sect = db.Sections.Find(student.SectionId);

            db.Entry(student).State = EntityState.Added;
            student.SectionCode     = sect.SectionCode;
            student.SectionName     = sect.SectionName;
            db.Students.Add(student);
            db.SaveChanges();
            var studentId = db.Entry(student).Entity.StudentId;

            return(student);
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
 public Section UpdateSection(int sectionId, Section section)
 {
     db.Entry(section).State = EntityState.Modified;
     db.SaveChanges();
     return(db.Sections.Find(sectionId));
 }
Esempio n. 4
0
 public async Task <bool> DeleteTraining(Training training)
 {
     context.Entry <Training>(training).State = EntityState.Deleted;
     return(await context.SaveChangesAsync() > 0);
 }