Ejemplo n.º 1
0
        public DatabaseCode AcceptBid(int bidID, Guid userID)
        {
            int          productID = bidRepository.GetProductIDForBid(bidID);
            ProductModel product   = productService.GetProduct(productID);

            if (productService.IsProductCreatedByUser(userID, productID))
            {
                var bidAcceptedResult = bidRepository.AcceptBid(bidID);

                if (bidAcceptedResult.dbCode == DatabaseCode.Updated)
                {
                    notificationService.Insert(new NotificationModel()
                    {
                        Information           = string.Format("Your bid for product {0} has been accepted! You will be contacted shortly by the seller.", product.ReferenceForView),
                        ReceivingUserID       = bidAcceptedResult.userID,
                        AdditionalInformation = JsonConvert.SerializeObject(new { productID })
                    });

                    (List <Bid> list, DatabaseCode dbCode)bidsRejected = bidRepository.DeclineBidsForProduct(userID, bidID, productID);

                    if (bidsRejected.dbCode == DatabaseCode.Updated)
                    {
                        foreach (var item in bidsRejected.list)
                        {
                            notificationService.Insert(new NotificationModel()
                            {
                                Information           = string.Format("Your bid for product {0} has been declined and the product has been awarded.", product.ReferenceForView),
                                ReceivingUserID       = item.userid,
                                AdditionalInformation = JsonConvert.SerializeObject(new { productID, bidID = item.id })
                            });
                        }
                    }

                    return(bidsRejected.dbCode);
                }
                return(DatabaseCode.Error);
            }
            return(DatabaseCode.NotAllowed);
        }