コード例 #1
0
        public ActionResult <CursusDTO> AddCursus([FromBody] CursusCreateUpdateDTO cursus)
        {
            var createdCursus = _cursusFacade.AddCursus(cursus);

            if (createdCursus == null)
            {
                return(Conflict("Cursus met die titel bestaat al."));
            }
            return(Created($"api/cursus/{createdCursus.ID}", createdCursus));
        }
コード例 #2
0
        public ActionResult <CursusCreateUpdateDTO> UpdateCursus([FromBody] CursusCreateUpdateDTO cursus, int id)
        {
            if (cursus.OrderNumber <= 0)
            {
                return(BadRequest("OrderNumber mag niet kleiner of gelijk zijn aan 0."));
            }

            var updatedCursus = _cursusFacade.UpdateCursus(cursus, id);

            if (updatedCursus == null)
            {
                return(Conflict($"Cursus met id:{id} bestaat niet."));
            }
            return(Ok(updatedCursus));
        }
コード例 #3
0
 public Cursus MapToModel(CursusCreateUpdateDTO dto)
 {
     return(new Cursus()
     {
         Beschrijving = dto.Beschrijving,
         Categorie = dto.Categorie,
         FotoURLCard = dto.FotoURLCard,
         LangeBeschrijving = dto.LangeBeschrijving,
         IsBuyable = dto.IsBuyable,
         Prijs = dto.Prijs,
         Titel = dto.Titel,
         Type = dto.Type,
         OrderNumber = dto.OrderNumber
     });
 }
コード例 #4
0
 public CursusDTO UpdateCursus(CursusCreateUpdateDTO cursus, int id)
 {
     var newCursus = _cursusMapper.MapToModel(cursus);
     newCursus.ID = id;
     var updatedCursus = _repositoryCursus.UpdateCursus(newCursus);
     if (updatedCursus == null)
         return null;
     try
     {
         _repositoryCursus.SaveChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
     return _cursusMapper.MapToDTO(updatedCursus);
 }
コード例 #5
0
 public CursusDTO AddCursus(CursusCreateUpdateDTO cursus)
 {
     var newCursus = _cursusMapper.MapToModel(cursus);
     var createdCursus = _repositoryCursus.AddCursus(newCursus);
     try
     {
         _repositoryCursus.SaveChanges();
     }
     catch (DbUpdateException)
     {
         return null;
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
     return _cursusMapper.MapToDTO(createdCursus);
 }