Exemple #1
0
        //[Authorize]
        public async Task <IActionResult> CreateTrade([FromBody] SaveTradeResource tradeResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var trade = mapper.Map <SaveTradeResource, Trade>(tradeResource);

            repository.Add(trade);
            await unitOfWork.CompleteAsync();

            var result = mapper.Map <Trade, SaveTradeResource>(trade);

            return(Ok(result));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateTrade(int id, [FromBody] SaveTradeResource tradeResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var trade = await repository.GetTradeAsync(id);

            if (trade == null)
            {
                return(NotFound());
            }

            mapper.Map <SaveTradeResource, Trade>(tradeResource, trade);

            await unitOfWork.CompleteAsync();

            var result = mapper.Map <Trade, LoadTradeResource>(trade);

            return(Ok(result));
        }