示例#1
0
        //[Authorize]
        public override async Task <CountryReply> Create(CountryCreateRequest request, ServerCallContext context)
        {
            //var currentUser = context.GetHttpContext().User;
            //throw new RpcException(new Status(StatusCode.InvalidArgument,"test"), "test");
            var createCountry = _mapper.Map <Country>(request);
            var country       = await _countryService.AddAsync(createCountry);

            return(_mapper.Map <CountryReply>(country));
        }
        public async Task <IActionResult> CreateCountry([FromBody] CountryCreateRequest request)
        {
            var res = await _context.Countries.AddAsync(_mapper.Map <Country>(request));

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(CreateCountry),
                                   await _context.Countries.ProjectTo <CountryGetAllResponse>(_mapper.ConfigurationProvider)
                                   .FirstOrDefaultAsync(x => x.Id == res.Entity.Id)));
        }
示例#3
0
        public IActionResult CreateCountry(CountryCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _countryRepository.CreateCountry(request);
            return(Ok());
        }
        public override async Task <CountryReply> Create(CountryCreateRequest request, ServerCallContext context)
        {
            var currentUser = context.GetHttpContext().User;

            try
            {
                var createCountry = _mapper.Map <Country>(request);
                var country       = await _countryService.AddAsync(createCountry);

                return(_mapper.Map <CountryReply>(country));
            }
            catch (Exception e)
            {
                throw new RpcException(Status.DefaultCancelled, e.Message);
            }
        }
        public override async Task <CountryReply> Create(CountryCreateRequest request, ServerCallContext context)
        {
            var currentUser = context.GetHttpContext().User;

            try
            {
                var createCountry = _mapper.Map <Country>(request);
                var country       = await _countryService.AddAsync(createCountry);

                return(_mapper.Map <CountryReply>(country));
            }
            catch (Exception e)
            {
                var httpContext = context.GetHttpContext();
                httpContext.Response.StatusCode = 500; // Required to fire Polly retry policy, else 200 will be returned
                throw new RpcException(Status.DefaultCancelled, e.Message);
            }
        }
示例#6
0
        public async Task <CountryCreateResponse> CreateCountryAsync(CountryCreateRequest request)
        {
            await this._builder.BuildAsync(request);

            var handler = this._handlers.SingleOrDefault(p => p.CanHandle(request));

            if (handler == null)
            {
                return(await Task.FromResult(default(CountryCreateResponse)));
            }

            var ev = handler.CreateEvent(request) as CountryCreatedEvent;

            PopulateBaseProperties(ev);

            CountryCreateResponse response;

            try
            {
                await this._processor.ProcessEventsAsync(new[] { ev });

                response = new CountryCreateResponse()
                {
                    Data = new CountryCreateResponseData()
                    {
                        Code = ev.CountryCode,
                        Name = ev.CountryName
                    }
                };
            }
            catch (Exception ex)
            {
                response = new CountryCreateResponse()
                {
                    Error = new ResponseError()
                    {
                        Message    = ex.Message,
                        StackTrace = ex.StackTrace
                    }
                };
            }

            return(await Task.FromResult(response));
        }