コード例 #1
0
        public async Task<IActionResult> Create([FromBody] CreateCoverRequest coverRequest)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(new {Messages = ModelState.Values.SelectMany(v => v.Errors)});
            }
            
            Cover limit = new Cover()
            {
                BrokerId = HttpContext.GetUserId(),
                Type = coverRequest.Type,
                LimitMultiplier = coverRequest.LimitMultiplier
            };

            var createdLimit = await _coverService.CreateAsync(limit);

            if (createdLimit == null) return BadRequest(new {Message = "Cover already exists"});
          
            var baseUrl = $"{HttpContext.Request.Scheme}://" + $"{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" +
                              ApiRoutes.Cover.Get.Replace("{coverId}", createdLimit.Entity.CoverId.ToString());
     
            return Created(locationUri, _mapper.Map<CoverResponse>(limit));
        }