Exemplo n.º 1
0
        public async Task <Response <BidDTO> > CreateNewBid(NewBidRequest bidRquest)
        {
            // create
            BidEntity bidEnitity = _mapper.Map <BidEntity>(bidRquest);

            bidEnitity.CreationDate = DateTime.Now;
            bidEnitity.Id           = Guid.NewGuid().ToString();

            // add to db
            if (mockedBidsSet.TryAdd(bidEnitity.Id, bidEnitity))
            {
                BidDTO bidDto = _mapper.Map <BidDTO>(bidEnitity);
                return(new Response <BidDTO> {
                    IsOperationSucceeded = true,
                    //SuccessOrFailureMessage = bidDto.GetType().GetProperties().ToList().ForEach(entity => { })
                    DTOObject = bidDto,
                });
            }
            else
            {
                return(new Response <BidDTO> {
                    IsOperationSucceeded = false,
                    SuccessOrFailureMessage = "failed to add to db"
                });
            }
        }
Exemplo n.º 2
0
        public async Task <Response> CreateNewBid(NewBidRequest bidRequest)
        {
            BidEntity bidEntity = _mapper.Map <BidEntity>(bidRequest);

            //TODO is this the time we want? (or global).
            bidEntity.CreationDate             = DateTime.Now;
            bidEntity.Id                       = Guid.NewGuid().ToString();
            bidEntity.UnitsCounter             = 0;
            bidEntity.PotenialSuplliersCounter = 0;
            bidEntity.Product.Id               = Guid.NewGuid().ToString();
            bidEntity.CurrentParticipancies    = new List <ParticipancyEntity>();
            bidEntity.CurrentProposals         = new List <SupplierProposalEntity>();

            _context.Bids.Add(bidEntity);
            try
            {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                //TODO log exception and return proper error message instead
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            BidDTO dto = _mapper.Map <BidDTO>(bidEntity);

            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }
Exemplo n.º 3
0
        public async Task <ActionResult> PostNewBid(NewBidRequest bid)
        {
            Response response = await this.bidsManager.CreateNewBid(bid).ConfigureAwait(false);

            if (response.IsOperationSucceeded)
            {
                return(this.StatusCode(StatusCodes.Status201Created, response.SuccessOrFailureMessage));
            }
            return(this.StatusCode(StatusCodes.Status403Forbidden, response.SuccessOrFailureMessage));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> PostNewBid(NewBidRequest bid)
        {
            bid.OwnerId = GetRequestUserId();
            Response response = await this.bidsManager.CreateNewBid(bid).ConfigureAwait(false);

            if (response.IsOperationSucceeded)
            {
                return(this.StatusCode(StatusCodes.Status201Created, response.SuccessOrFailureMessage));
            }
            return(this.StatusCode(StatusCodes.Status500InternalServerError, response.SuccessOrFailureMessage));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> PostNewBid(NewBidRequest bid)
        {
            string ownerId = this.GetUserId();

            if (bid.OwnerId != ownerId)
            {
                return(this.StatusCode(StatusCodes.Status401Unauthorized, "token id dosent match input id"));
            }

            Response response = await this.bidsManager.CreateNewBid(bid).ConfigureAwait(false);

            if (response.IsOperationSucceeded)
            {
                return(this.StatusCode(StatusCodes.Status201Created, response.SuccessOrFailureMessage));
            }
            return(this.StatusCode(StatusCodes.Status403Forbidden, response.SuccessOrFailureMessage));
        }
Exemplo n.º 6
0
        public async Task <Response> CreateNewBid(NewBidRequest bidRequest)
        {
            BidEntity bidEntity = _mapper.Map <BidEntity>(bidRequest);

            PopulateBidEntity(bidEntity);

            ProductEntity existingProduct = await FindExistingProductAsync(bidRequest.Product);

            if (existingProduct != null)
            {
                bidEntity.Product = existingProduct;
            }

            if (!(await this.isValidNewBidAsync(bidEntity)))
            {
                // new Response Error Code
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = "Not Valid Group: This owner has an active bid of this product / There are too many groups for this product / There is an equivalent available group already"
                });
            }

            _context.Bids.Add(bidEntity);
            try
            {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                //TODO log exception and return proper error message instead
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }
Exemplo n.º 7
0
 Task <Response> IBidsManager.CreateNewBid(NewBidRequest productBid)
 {
     throw new NotImplementedException();
 }