Example #1
0
        public IActionResult Create([FromServices] LawsuitService service, [FromBody] LawsuitDTO lawsuitDto)
        {
            service.LawsuitPrevalidations(lawsuitDto, null);

            Lawsuit lawsuit        = Mapper.Map <Lawsuit>(lawsuitDto);
            var     createdLawsuit = service.Add <LawsuitValidator>(lawsuit);
            var     response       = Mapper.Map <Lawsuit, LawsuitView>(createdLawsuit);

            if (response == null)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok(response));
            }
        }
Example #2
0
        public IActionResult Update([FromServices] LawsuitService service, [FromBody] LawsuitDTO lawsuitDto, int id)
        {
            service.LawsuitPrevalidations(lawsuitDto, id);

            Lawsuit lawsuit = service.GetById(x => x.IdLawsuit == id);

            if (lawsuit == null)
            {
                return(NotFound());
            }

            var mappedLawsuit  = Mapper.Map(lawsuitDto, lawsuit);
            var updatedLawsuit = service.Update <LawsuitValidator>(mappedLawsuit);
            var response       = Mapper.Map <Lawsuit, LawsuitView>(updatedLawsuit);

            return(Ok(response));
        }