コード例 #1
0
 public ActionResult <Afbeelding> Put(int id, AfbeeldingDTO DTO)
 {
     try
     {
         Afbeelding a = _afbeeldingRepository.GetBy(id);
         if (a == null)
         {
             return(BadRequest("De afbeelding die u wenst te wijzigen bestaat niet"));
         }
         Lesmateriaal lesMateriaal = _lesmateriaalRepository.GetBy(DTO.LesMateriaalId);
         if (lesMateriaal == null)
         {
             return(BadRequest("Het opgegeven lesmateriaal bestaat niet!"));
         }
         a.LesmateriaalId = DTO.LesMateriaalId;
         a.Adres          = DTO.Adres;
         _afbeeldingRepository.Update(a);
         _afbeeldingRepository.SaveChanges();
         return(a);
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #2
0
 public ActionResult <Afbeelding> Post(AfbeeldingDTO DTO)
 {
     try
     {
         if (_lesmateriaalRepository.GetBy(DTO.LesMateriaalId) == null)
         {
             return(BadRequest("Het opgegeven lesmateriaal kon niet worden gevonden!"));
         }
         Afbeelding a = new Afbeelding(DTO.LesMateriaalId, DTO.Adres);
         _afbeeldingRepository.Add(a);
         _afbeeldingRepository.SaveChanges();
         return(CreatedAtAction(nameof(GetBy), new { id = a.Id }, a));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }