public async Task <IActionResult> CreateUser([FromBody] GateDTO gateDto) { var command = new CreateGateCommand(gateDto.Identity, gateDto.Description); await mediator.Send(command); return(Ok(new { message = "Gate created" })); }
public async Task <Result <bool> > Handle(CreateGateCommand request, CancellationToken cancellationToken) { try { var account = await _accountRepository.GetAccountByName(request.AccountName); var gateType = await _gateTypeRepository.GetGateTypeByName(request.Name); var newGate = new Gate { GateTypeId = gateType == null ? 1 : gateType.Id, Name = request.Name, ServiceId = Guid.NewGuid().ToString(), CharacteristicId = Guid.NewGuid().ToString(), CreatedBy = request.CreatedBy, CreatedAt = DateTime.UtcNow }; if (account != null) { newGate.AccountId = account.Id; } var res = await _gateRepository.Create(newGate); return(Result <bool> .Ok(res)); } catch (Exception e) { return(Result <bool> .Failure(e.Message)); } }
public async Task <IActionResult> CreateGate([FromBody] CreateGateCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } command.CreatedBy = HttpContext.User.Identity.Name; var result = await _mediator.Send(command); return(StatusCodeResult(result)); }