public List <Lawsuit> GetAllFilter(LawsuitDTO lawsuitDto) { List <Lawsuit> result = new List <Lawsuit>(); result = GetAll(x => (x.CaseNumber.Equals(lawsuitDto.CaseNumber) || string.IsNullOrEmpty(lawsuitDto.CaseNumber)) && (x.CourtName.Contains(lawsuitDto.CourtName) || string.IsNullOrEmpty(lawsuitDto.CourtName)) && (x.ResponsibleName.Contains(lawsuitDto.ResponsibleName) || string.IsNullOrEmpty(lawsuitDto.ResponsibleName))).ToList(); return(result); }
public IActionResult GetAll([FromServices] LawsuitService service, LawsuitDTO lawsuitDto) { List <Lawsuit> lawsuits = service.GetAllFilter(lawsuitDto); var response = Mapper.Map <List <Lawsuit>, List <LawsuitView> >(lawsuits); if (!response.Any()) { return(NoContent()); } return(Ok(response)); }
public void CreateWithInvalidCaseNumberFormat() { LawsuitDTO lawsuitDto = new LawsuitDTO { CaseNumber = "123-12.12.1.12.123", CourtName = "CNJ", ResponsibleName = "Renato Mesquita", }; var result = _fixture.Controller.Create(_fixture.ServiceMock.Object, lawsuitDto); Assert.IsType <BadRequestResult>(result); }
public void LawsuitPrevalidations(LawsuitDTO lawsuitDto, int?updatedId) { if (lawsuitDto != null) { // 1 - Number case exists List <Lawsuit> lawsuits = GetAll(x => (x.CaseNumber == lawsuitDto.CaseNumber) && (x.IdLawsuit != updatedId || updatedId == null)).ToList(); if (lawsuits.Count > 0) { throw new ValidationException("Case number exists."); } } }
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)); } }
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)); }
public void CreateWithWithTheSameCaseNumber() { LawsuitDTO lawsuitDto1 = new LawsuitDTO { CaseNumber = "1234567-12.1234.1.12.1234", CourtName = "CNJ", ResponsibleName = "Renato Mesquita", }; LawsuitDTO lawsuitDto2 = new LawsuitDTO { CaseNumber = "1234567-12.1234.1.12.1234", CourtName = "TJ", ResponsibleName = "Renato Mesquita 2", }; _fixture.Controller.Create(_fixture.ServiceMock.Object, lawsuitDto1); var result = _fixture.Controller.Create(_fixture.ServiceMock.Object, lawsuitDto2); Assert.IsType <BadRequestResult>(result); }