コード例 #1
0
ファイル: BidsManager.cs プロジェクト: yotamc4/GoogleWorkShop
        public async Task <Response> AddBuyer(BidBuyerJoinRequest bidBuyerJoinRequest)
        {
            BidEntity bid = await _context.Bids.Where(b => b.Id == bidBuyerJoinRequest.BidId).Include(b => b.CurrentParticipancies).FirstOrDefaultAsync().ConfigureAwait(false);

            if (bid == null)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = BidNotFoundFailString
                });
            }
            bid.CurrentParticipancies.Add(new ParticipancyEntity {
                BidId      = bidBuyerJoinRequest.BidId,
                BuyerId    = bidBuyerJoinRequest.BuyerId,
                NumOfUnits = bidBuyerJoinRequest.Items
            });
            bid.UnitsCounter += bidBuyerJoinRequest.Items;
            try
            {
                _context.Bids.Update(bid);
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }
コード例 #2
0
        public async Task <Response> DeleteBuyer(string buyerId)
        {
            var buyer = await _context.Buyers.Where(b => b.Id == buyerId).Include(b => b.CurrentParticipancies).FirstOrDefaultAsync().ConfigureAwait(false);

            //var buyer = await _context.Buyers.Where(b => b.Id == buyerId).Include(b => b.CurrentParticipancies).Include(b => b.BuyerAccountDetails).Include(b => b.FacebookAccount).FirstOrDefaultAsync().ConfigureAwait(false);
            if (buyer == null)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = BuyerNotFoundFailString
                });
            }
            _context.Buyers.Remove(buyer);
            try
            {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }
コード例 #3
0
        public async Task <Response> DeleteSupplier(string supplierId)
        {
            var supplier = await _context.Suppliers.Where(s => s.Id == supplierId).Include(b => b.CurrentProposals).FirstOrDefaultAsync().ConfigureAwait(false);

            if (supplier == null)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = SupplierNotFoundFailString
                });
            }
            _context.Suppliers.Remove(supplier);
            try
            {
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }
コード例 #4
0
        public async Task <Response> CreateBuyer(NewUserRequest request)
        {
            BuyerEntity newBuyer = _mapper.Map <BuyerEntity>(request);

            try
            {
                _context.Buyers.Add(newBuyer);
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }
コード例 #5
0
        public async Task <Response> AddBuyer(BidBuyerJoinRequest bidBuyerJoinRequest)
        {
            BidEntity bid = await _context.Bids.Where(b => b.Id == bidBuyerJoinRequest.BidId).Include(b => b.CurrentParticipancies).Include(b => b.Product).FirstOrDefaultAsync().ConfigureAwait(false);

            if (bid == null)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = BidNotFoundFailString
                });
            }
            if (!await this.isValidJoinAsync(bid.Product, bidBuyerJoinRequest.BuyerId))
            {
                // new Response Error Code
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = "Buyer already participates in an active bid with this product"
                });
            }
            bid.CurrentParticipancies.Add(_mapper.Map <ParticipancyEntity>(bidBuyerJoinRequest));
            bid.UnitsCounter += bidBuyerJoinRequest.NumOfUnits;
            try
            {
                _context.Bids.Update(bid);
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage()
            });
        }