Esempio n. 1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            CreateCoverRequest cover = (CreateCoverRequest)validationContext.ObjectInstance;

            if (cover.LimitMultiplier < 1 || cover.LimitMultiplier > 3)
            {
                return(new ValidationResult(GetErrorMessage(cover.LimitMultiplier)));
            }

            return(ValidationResult.Success);
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            CreateCoverRequest cover = (CreateCoverRequest)validationContext.ObjectInstance;

            if (!_supportedCovers.Contains(cover.Type))
            {
                return(new ValidationResult(GetErrorMessage(cover.Type)));
            }

            return(ValidationResult.Success);
        }
Esempio n. 3
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));
        }