Beispiel #1
0
        public async Task <IActionResult> OpenBid([FromBody] BidCreationDto bidDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { message = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage) }));
            }

            var createBid = _mapper.Map <Bid>(bidDto);

            try
            {
                var userId = User.FindFirstValue(ClaimTypes.Name);
                if (bidDto.FreelancerId != userId)
                {
                    throw new InvalidBid("User doesn't have access to this bid");
                }

                var createdBid = await _bidService.Open(createBid);

                return(Ok(createdBid));
            }
            catch (UserNotFound)
            {
                return(NotFound(new MessageObj("User not found")));
            }
            catch (EnvironmentNotSet)
            {
                throw;
            }
            catch (Exception e)
            {
                return(BadRequest(new MessageObj(e.Message)));
            }
        }