public IActionResult Post(CorrActionDto corrAction) { ServiceResponse <CorrActionDto> serviceResponse = _corrActionService.AddCorrAction(corrAction); if (serviceResponse.Data == null) { return(BadRequest(serviceResponse.Message)); } return(Ok(serviceResponse)); }
public static void Initialize(DataContext context, IMapper mapper) { NonConfService nonConfService = new NonConfService(context, mapper); CorrActionService corrActionService = new CorrActionService(context, mapper); NonConfCorrActionsService nonConfCorrActionsService = new NonConfCorrActionsService(context, mapper); context.Database.EnsureCreated(); if (context.nonConfs.Any()) { return; } //Insere as NonConfs var newNonConfs = new NonConf[] { new NonConf(), new NonConf { Status = 2 }, new NonConf() }; foreach (NonConf n in newNonConfs) { nonConfService.AddNonConf(n); } //Insere as CorrActions var newCorrActions = new CorrActionDto[] { new CorrActionDto { Description = "Do Anything 01." }, new CorrActionDto { Description = "Do Anything 02." } }; foreach (CorrActionDto c in newCorrActions) { corrActionService.AddCorrAction(c); } //Relaciona uma CorrAction com uma NonConf nonConfCorrActionsService.AddNonConfCorrActions(new NonConfCorrActionsDto() { NonconfId = 1, CorractionId = 1 }); }
public ServiceResponse <CorrActionDto> AddCorrAction(CorrActionDto corrAction) { try { _context.corrActions.Add(_mapper.Map <CorrAction>(corrAction)); _context.SaveChanges(); serviceResponse.Data = _mapper.Map <CorrActionDto>(_context.corrActions.OrderByDescending(c => c.Id).First()); serviceResponse.Message = "A Ação foi criada com sucesso!"; } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = "Não foi possível criar a nova Ação. Exception: " + ex; } return(serviceResponse); }
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); }