Esempio n. 1
0
        public IActionResult Create([FromBody] SalutationDTO dto)
        {
            var Res = _Mapper.Map <Salutation>(dto);

            try
            {
                var salutation = _salutationRepository.SaveOrUpdateAsync(Res);
                return(Ok(salutation));
            }
            catch (AppException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Details(int?id, SalutationDTO dto)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var salutation = await _salutationRepository.GetByIdAsync(id);

            var sal = _Mapper.Map <SalutationDTO>(salutation);

            if (salutation == null)
            {
                return(NotFound());
            }
            return(Ok(sal));
        }
Esempio n. 3
0
        public IActionResult Update(int id, [FromBody] SalutationDTO dto)
        {
            // map dto to entity and set id
            var salutation = _Mapper.Map <Salutation>(dto);

            salutation.Id = id;

            try
            {
                // save
                _salutationRepository.UpdateAsync(salutation, id);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(ex.Message));
            }
        }