Exemplo n.º 1
0
        public IActionResult Create([FromBody] Candidate_Dto candidateDto)
        {
            // map dto to entity
            var candidate = Mapper.Map <Candidate>(candidateDto);

            try
            {
                // save
                Repository.Insert(candidate);
                return(Ok(candidate));
            }
            catch (Exception ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemplo n.º 2
0
        [HttpPut("{id}")]// sa trimit si vechea cheie pe care vreau sa o modific
        public IActionResult Update([FromBody] Candidate_Dto candidateDto, int id)
        {
            // map dto to entity and set id
            var candidate = Mapper.Map <Candidate>(candidateDto);

            candidate.IdCandidate = id;

            try
            {
                // save
                Repository.Update(candidate);
                return(Ok(candidate));
            }
            catch (Exception ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }