public async Task <IActionResult> PostAsync([FromBody] CreateWeaponDto item) { await _mediator.Send(new CreateWeaponCommand() { CreateWeapon = item }); return(Ok()); }
public async Task <IActionResult> CreateNewWeapon(CreateWeaponDto newWeaponDto) { ServiceResponse <GetWeaponDto> response = await _weaponService.CreateNewWeapon(newWeaponDto); if (!response.Success) { return(BadRequest(response)); } return(Ok(response)); }
public async Task <ApiResponse <object> > Create(CreateWeaponDto request) { var command = new CreateWeaponCommand { Name = request.Name, Damage = request.Damage }; await _operationMediator.HandleAsync(command); var location = Url.Link(GetByIdRouteName, new { id = command.GeneratedId }); return(ApiResponse.Created(location, command.GeneratedId)); }
public async Task <ServiceResponse <GetWeaponDto> > CreateNewWeapon(CreateWeaponDto newWeaponDto) { ServiceResponse <GetWeaponDto> response = new ServiceResponse <GetWeaponDto> (); try { Weapon weapon = _mapper.Map <Weapon> (newWeaponDto); weapon.Uuid = Guid.NewGuid(); _context.Weapons.Add(weapon); await _context.SaveChangesAsync(); response.Data = _mapper.Map <GetWeaponDto> (weapon); } catch (System.Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }