Exemple #1
0
        public ActionResult <Lesmateriaal> Put(int id, LesmateriaalDTO DTO)
        {
            try
            {
                Lesmateriaal l = _lesmateriaalRepository.GetBy(id);
                if (l == null)
                {
                    return(BadRequest("Het opgegeven lesmateriaal kon niet worden gevonden!"));
                }


                l.Graad = DTO.Graad;
                l.Naam  = DTO.Naam;
                l.OefeningUitlegTekst = DTO.OefeningUitlegTekst;
                l.Categorie           = DTO.Categorie;
                l.Afbeeldingen        = DTO.Afbeeldingen;
                //if(DTO.Afbeeldingen != null)
                //foreach (Afbeelding afb in DTO.Afbeeldingen)
                //{
                //    afbeeldingRepository.Add(afb);
                //    afbeeldingRepository.SaveChanges();
                //}
                l.Videos      = DTO.Videos;
                l.Commentaren = DTO.Commentaren;
                _lesmateriaalRepository.Update(l);
                _lesmateriaalRepository.SaveChanges();
                return(CreatedAtAction(nameof(GetBy), new { id = l.Id }, l));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #2
0
 public IActionResult Post(LesmateriaalDTO DTO)
 {
     try
     {
         Lesmateriaal l = new Lesmateriaal(DTO.Graad, DTO.Naam, DTO.OefeningUitlegTekst,
                                           DTO.Categorie, DTO.Afbeeldingen, DTO.Videos, DTO.Commentaren);
         if (DTO.Afbeeldingen == null)
         {
             DTO.Afbeeldingen = new List <Afbeelding>();
         }
         if (DTO.Videos == null)
         {
             DTO.Videos = new List <Video>();
         }
         if (DTO.Commentaren == null)
         {
             DTO.Commentaren = new List <Commentaar>();
         }
         _lesmateriaalRepository.Add(l);
         _lesmateriaalRepository.SaveChanges();
         return(CreatedAtAction(nameof(GetBy), new { id = l.Id }, l));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }