Ejemplo n.º 1
0
        public async Task <ActionResult <CreateCommand.Result> > Create(CreateCommandDto dto)
        {
            var command = new CreateCommand(new SupplierName(dto.Name));
            var result  = await _mediator.Send(command);

            return(StatusCode(StatusCodes.Status201Created, result));
        }
        public async Task <ActionResult <CreateCommand.Result> > Create(CreateCommandDto dto)
        {
            var command = _mapper.Map <CreateCommand>(dto);
            var result  = await _mediator.Send(command);

            return(StatusCode(StatusCodes.Status201Created, result));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CreateCommand.Result> > Create(CreateCommandDto dto)
        {
            var command = new CreateCommand(new OrderNo(dto.OrderNo), dto.SupplierId.Value);
            var result  = await _mediator.Send(command);

            return(StatusCode(StatusCodes.Status201Created, result));
        }
Ejemplo n.º 4
0
        public ActionResult <CommandDto> CreateCommand(CreateCommandDto dto)
        {
            var model = _map.Map <Command>(dto);

            _repo.CreateCommand(model);
            _repo.SaveChanges();

            var CmdDto = _map.Map <CommandDto>(model);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = CmdDto.Id }, CmdDto));

            //return Ok(CmdDto);
        }
Ejemplo n.º 5
0
        public ActionResult<CommandReadDto> CreateCommand(CreateCommandDto createCommandDto)
        {
            //mapping CreateCommnad to Command resource ....Map-> createCommandDto to Command
            var commnad = _mapper.Map<Command>(createCommandDto);
            _repository.CreateCommand(commnad);
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map<CommandReadDto>(commnad);

            //getting a single resource location -getbyId and creatng anonymous object ->new{id=commandReadDto.Id} and passing dto object
            return CreatedAtRoute(nameof(GetById), new { id = commandReadDto.Id }, commandReadDto);

            //  return Ok(commandReadDto);
        }
        public void Execute(CreateCommandDto request)
        {
            if (!_context.Ads.Any(x => x.Id == request.AdId))
            {
                throw new EntityNotFoundException("Ad");
            }

            _context.Comments.Add(new Comment()
            {
                AdId     = request.AdId,
                Comments = request.Comment,
                UserId   = request.UserId
            });
            _context.SaveChanges();
        }