Exemple #1
0
        public async Task <IActionResult> Get(int id)
        {
            var regra = await _unitOfWork.Regras.GetByIdAsync(id);

            if (regra.IsAtivo == true)
            {
                return(Ok(RegraMapper.ModelToResource(regra)));
            }
            else
            {
                return(NoContent());
            }
        }
Exemple #2
0
        public async Task <IActionResult> GetAll()
        {
            var regras = await _unitOfWork.Regras.GetAllAsync();

            List <RegraResource> regraResource = new List <RegraResource>();

            if (regras == null)
            {
                return(NoContent());
            }
            foreach (var regra in regras)
            {
                if (regra.IsAtivo == true)
                {
                    regraResource.Add(RegraMapper.ModelToResource(regra));
                }
            }
            return(Ok(regraResource));
        }
Exemple #3
0
        public async Task <IActionResult> Edit(int id, [FromBody] RegraResource regraResource)
        {
            try
            {
                var regra = await _unitOfWork.Regras.GetByIdAsync(id);

                if (ModelState.IsValid)
                {
                    regra = RegraMapper.ResourceToModel(regraResource, regra);
                    await _unitOfWork.CompleteAsync();

                    RegraMapper.ModelToResource(regra);
                }
                return(Ok(regra));
            }
            catch (Exception e)
            {
                LogError.LogErrorWithSentry(e);
                return(BadRequest(ModelState));
            }
        }
Exemple #4
0
        public async Task <IActionResult> Create([FromBody] RegraResource regraResource)
        {
            if (regraResource == null)
            {
                return(NotFound());
            }
            try
            {
                var regra = new Regra();
                if (ModelState.IsValid)
                {
                    regra = RegraMapper.ResourceToModel(regraResource, regra);
                }
                _unitOfWork.Regras.Add(regra);
                await _unitOfWork.CompleteAsync();

                return(Ok(regra));
            }
            catch (Exception exception)
            {
                LogError.LogErrorWithSentry(exception);
                return(BadRequest());
            }
        }