Ejemplo n.º 1
0
        public ServiceResponse <GetNonConfDto> AddNonConfCorrActions(NonConfCorrActionsDto nonConfCorrActions)
        {
            NonConf    nonConf    = _context.nonConfs.Find(nonConfCorrActions.NonconfId);
            CorrAction corrAction = _context.corrActions.Find(nonConfCorrActions.CorractionId);

            if (NonConfCorrActionsValidator(nonConf, corrAction) == false)
            {
                return(serviceResponse);
            }

            try
            {
                NonConfCorrActions newNonConfCorrActions = new NonConfCorrActions
                {
                    NonConf    = nonConf,
                    CorrAction = corrAction
                };

                _context.nonConfCorrActions.Add(newNonConfCorrActions);
                _context.SaveChanges();

                serviceResponse.Data = _mapper.Map <GetNonConfDto>(nonConf);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "Não foi possível processar a requisição. Exception: " + ex.Message;
            }

            return(serviceResponse);
        }
        public IActionResult AddNonConfCorrAction(NonConfCorrActionsDto newNonConfCorrAction)
        {
            ServiceResponse <GetNonConfDto> serviceResponse = _nonConfCorrActionsService.AddNonConfCorrActions(newNonConfCorrAction);

            if (serviceResponse.Success == false)
            {
                return(BadRequest(serviceResponse.Message));
            }

            return(Ok(serviceResponse));
        }
Ejemplo n.º 3
0
        public void Get_ShouldReturnFalseIfIdNotExist()
        {
            _nonConfService.AddNonConf(new NonConf()
            {
                Id = 1
            });
            _corrActionService.AddCorrAction(new CorrActionDto()
            {
                Id = 1, Description = "Do Anything."
            });

            NonConfCorrActionsDto nonConfCorrActions = new NonConfCorrActionsDto()
            {
                NonconfId = 2, CorractionId = 1
            };

            _serviceResponse = _nonConfCorrActionsService.AddNonConfCorrActions(nonConfCorrActions);

            Assert.False(_serviceResponse.Success);
        }
Ejemplo n.º 4
0
        public void Post_ShouldNotAllowInsertCorrActionsInClosedNonConf()
        {
            _nonConfService.AddNonConf(new NonConf()
            {
                Id = 1, Status = 1
            });
            _corrActionService.AddCorrAction(new CorrActionDto()
            {
                Id = 1, Description = "Do Anything."
            });

            NonConfCorrActionsDto nonConfCorrActions = new NonConfCorrActionsDto()
            {
                NonconfId = 2, CorractionId = 1
            };

            _serviceResponse = _nonConfCorrActionsService.AddNonConfCorrActions(nonConfCorrActions);

            Assert.False(_serviceResponse.Success);
        }
Ejemplo n.º 5
0
        public void Post_ShouldInsertANewCorrActionInANonConf()
        {
            CorrActionDto corrAction = new CorrActionDto()
            {
                Id = 1, Description = "Do Anything."
            };

            _nonConfService.AddNonConf(new NonConf()
            {
                Id = 1
            });
            _corrActionService.AddCorrAction(corrAction);

            NonConfCorrActionsDto nonConfCorrActions = new NonConfCorrActionsDto()
            {
                NonconfId = 1, CorractionId = 1
            };

            _nonConfCorrActionsService.AddNonConfCorrActions(nonConfCorrActions);

            List <CorrActionDto> corrActionsInNonConf = _nonConfService.GetNonConfById(1).Data.CorrActions;

            Assert.Equal(corrAction.Id, corrActionsInNonConf[0].Id);
        }