Пример #1
0
        public async Task <IActionResult> PostAsync([FromBody] CreateWeaponDto item)
        {
            await _mediator.Send(new CreateWeaponCommand()
            {
                CreateWeapon = item
            });

            return(Ok());
        }
Пример #2
0
        public async Task <IActionResult> CreateNewWeapon(CreateWeaponDto newWeaponDto)
        {
            ServiceResponse <GetWeaponDto> response = await _weaponService.CreateNewWeapon(newWeaponDto);

            if (!response.Success)
            {
                return(BadRequest(response));
            }
            return(Ok(response));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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);
        }