Beispiel #1
0
        private static MailMessage GeneratePendingOfferEmail(string rioUrl, TradeDto currentTrade,
                                                             OfferDto offer, PostingDto posting, SitkaSmtpClientService smtpClient)
        {
            var offerAction = currentTrade.CreateAccount.AccountID == offer.CreateAccount.AccountID
                ? posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "sell" : "buy"
                : posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "buy" : "sell";
            var toAccount   = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? currentTrade.CreateAccount : posting.CreateAccount;
            var fromAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID
                ? posting.CreateAccount
                : currentTrade.CreateAccount;

            var properPreposition = offerAction == "sell" ? "to" : "from";
            var messageBody       =
                $@"
Hello,
<br /><br />
An offer to {offerAction} water {properPreposition} Account #{fromAccount.AccountNumber} ({fromAccount.AccountName}) has been presented for your review. 
<br /><br />
<a href=""{rioUrl}/trades/{currentTrade.TradeNumber}"">Respond to this offer</a>
{smtpClient.GetDefaultEmailSignature()}";
            var mailMessage = new MailMessage
            {
                Subject = "New offer to review",
                Body    = messageBody
            };

            foreach (var user in toAccount.Users)
            {
                mailMessage.To.Add(new MailAddress(user.Email, user.FullName));
            }
            return(mailMessage);
        }
Beispiel #2
0
        private static MailMessage GenerateRescindedOfferEmail(string rioUrl, OfferDto offer,
                                                               TradeDto currentTrade,
                                                               PostingDto posting, SitkaSmtpClientService smtpClient)
        {
            var offerAction = currentTrade.CreateAccount.AccountID == offer.CreateAccount.AccountID
                ? posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "sell" : "buy"
                : posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "buy" : "sell";

            var toAccount   = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? currentTrade.CreateAccount : posting.CreateAccount;
            var fromAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID
                ? posting.CreateAccount
                : currentTrade.CreateAccount;

            var properPreposition = offerAction == "sell" ? "to" : "from";
            var messageBody       =
                $@"
Hello,
<br /><br />
An offer to {offerAction} water {properPreposition} Account #{fromAccount.AccountNumber} ({fromAccount.AccountName}) was rescinded by the other party. You can see details of your transactions in the Water Accounting Platform Landowner Dashboard. 
<br /><br />
<a href=""{rioUrl}/landowner-dashboard/{toAccount.AccountNumber}"">View Landowner Dashboard</a>
{smtpClient.GetDefaultEmailSignature()}";
            var mailMessage = new MailMessage
            {
                Subject = $"Trade {currentTrade.TradeNumber} Rescinded",
                Body    = messageBody
            };

            foreach (var user in toAccount.Users)
            {
                mailMessage.To.Add(new MailAddress(user.Email, user.FullName));
            }
            return(mailMessage);
        }
        private static void SetMostRecentOfferOfType(OfferDto mostRecentOffer, PostingDto mostRecentPosting,
                                                     MarketMetricsDto marketMetricsDto, Expression <Func <MarketMetricsDto, int?> > quantityFunc, Expression <Func <MarketMetricsDto, decimal?> > priceFunc)
        {
            var quantityExpression = (MemberExpression)quantityFunc.Body;
            var quantityProperty   = (PropertyInfo)quantityExpression.Member;
            var priceExpression    = (MemberExpression)priceFunc.Body;
            var priceProperty      = (PropertyInfo)priceExpression.Member;

            if (mostRecentOffer == null && mostRecentPosting == null)
            {
                quantityProperty.SetValue(marketMetricsDto, null);
                priceProperty.SetValue(marketMetricsDto, null);
            }
            else
            {
                var mostRecentOfferDate   = mostRecentOffer?.OfferDate;
                var mostRecentPostingDate = mostRecentPosting?.PostingDate;
                if (mostRecentPostingDate != null && mostRecentPostingDate > mostRecentOfferDate)
                {
                    quantityProperty.SetValue(marketMetricsDto, mostRecentPosting.Quantity);
                    priceProperty.SetValue(marketMetricsDto, mostRecentPosting.Price);
                }
                else
                {
                    quantityProperty.SetValue(marketMetricsDto, mostRecentOffer?.Quantity);
                    priceProperty.SetValue(marketMetricsDto, mostRecentOffer?.Price);
                }
            }
        }
Beispiel #4
0
 public static bool HasOpenOfferByAccountID(RioDbContext dbContext, PostingDto posting, int createAccountID)
 {
     return(dbContext.Trade.Any(x =>
                                x.PostingID == posting.PostingID &&
                                x.CreateAccountID == createAccountID &&
                                (x.TradeStatusID == (int)TradeStatusEnum.Accepted ||
                                 x.TradeStatusID == (int)TradeStatusEnum.Countered)));
 }
        public IHttpActionResult CreatePost(PostingDto postingDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var posting = Mapper.Map <PostingDto, Posting>(postingDto);

            _context.Postings.Add(posting);
            _context.SaveChanges();

            postingDto.Id = posting.Id;

            return(Created(new Uri(Request.RequestUri, "/" + posting.Id), postingDto));
        }
        public IHttpActionResult UpdatePost(int id, PostingDto postingDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var postingInDb = _context.Postings.SingleOrDefault(p => p.Id == id);

            if (postingInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(postingDto, postingInDb);



            _context.SaveChanges();

            return(Ok());
        }
Beispiel #7
0
        public static WaterTransferDto CreateNew(RioDbContext dbContext, OfferDto offerDto, TradeDto tradeDto, PostingDto postingDto)
        {
            var waterTransfer = new WaterTransfer
            {
                OfferID             = offerDto.OfferID,
                AcreFeetTransferred = offerDto.Quantity,
                TransferDate        = offerDto.OfferDate
            };

            var waterTransferRegistrationBuyer = new WaterTransferRegistration()
            {
                WaterTransfer       = waterTransfer,
                WaterTransferTypeID = (int)WaterTransferTypeEnum.Buying,
                StatusDate          = DateTime.Now,
                WaterTransferRegistrationStatusID = (int)WaterTransferRegistrationStatusEnum.Pending
            };
            var waterTransferRegistrationSeller = new WaterTransferRegistration()
            {
                WaterTransfer       = waterTransfer,
                WaterTransferTypeID = (int)WaterTransferTypeEnum.Selling,
                StatusDate          = DateTime.Now,
                WaterTransferRegistrationStatusID = (int)WaterTransferRegistrationStatusEnum.Pending
            };

            if (postingDto.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToSell)
            {
                waterTransferRegistrationSeller.AccountID = postingDto.CreateAccount.AccountID;
                waterTransferRegistrationBuyer.AccountID  = tradeDto.CreateAccount.AccountID;
            }
            else
            {
                waterTransferRegistrationSeller.AccountID = tradeDto.CreateAccount.AccountID;
                waterTransferRegistrationBuyer.AccountID  = postingDto.CreateAccount.AccountID;
            }

            dbContext.WaterTransfer.Add(waterTransfer);
            dbContext.WaterTransferRegistration.Add(waterTransferRegistrationBuyer);
            dbContext.WaterTransferRegistration.Add(waterTransferRegistrationSeller);
            dbContext.SaveChanges();
            dbContext.Entry(waterTransfer).Reload();

            return(GetByWaterTransferID(dbContext, waterTransfer.WaterTransferID));
        }
Beispiel #8
0
        private static List <MailMessage> GenerateAcceptedOfferEmail(string rioUrl, OfferDto offer,
                                                                     TradeDto currentTrade, PostingDto posting, WaterTransferDto waterTransfer, SitkaSmtpClientService smtpClient)
        {
            AccountDto buyer;
            AccountDto seller;

            if (currentTrade.CreateAccount.AccountID == posting.CreateAccount.AccountID)
            {
                if (posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy)
                {
                    buyer  = posting.CreateAccount;
                    seller = currentTrade.CreateAccount;
                }
                else
                {
                    buyer  = currentTrade.CreateAccount;
                    seller = posting.CreateAccount;
                }
            }
            else
            {
                if (posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy)
                {
                    buyer  = posting.CreateAccount;
                    seller = currentTrade.CreateAccount;
                }
                else
                {
                    buyer  = currentTrade.CreateAccount;
                    seller = posting.CreateAccount;
                }
            }


            var mailMessages = new List <MailMessage>();
            var messageBody  = $@"Your offer to trade water has been accepted.
<ul>
    <li><strong>Buyer:</strong> {buyer.AccountName} ({string.Join(", ",  buyer.Users.Select(x=>x.Email))})</li>
    <li><strong>Seller:</strong> {seller.AccountName} ({string.Join(", ", seller.Users.Select(x => x.Email))})</li>
    <li><strong>Quantity:</strong> {offer.Quantity} acre-feet</li>
    <li><strong>Unit Price:</strong> {offer.Price:$#,##0.00} per acre-foot</li>
    <li><strong>Total Price:</strong> {(offer.Price * offer.Quantity):$#,##0.00}</li>
</ul>
To finalize this transaction, the buyer and seller must complete payment and any other terms of the transaction. Once payment is complete, the trade must be confirmed by both parties within the Water Accounting Platform before the district will recognize the transfer.
<br /><br />
<a href=""{rioUrl}/register-transfer/{waterTransfer.WaterTransferID}"">Confirm Transfer</a>
{smtpClient.GetDefaultEmailSignature()}";
            var mailTos      = (new List <AccountDto> {
                buyer, seller
            }).SelectMany(x => x.Users);

            foreach (var mailTo in mailTos)
            {
                var mailMessage = new MailMessage
                {
                    Subject = $"Trade {currentTrade.TradeNumber} Accepted",
                    Body    = $"Hello {mailTo.FullName},<br /><br />{messageBody}"
                };
                mailMessage.To.Add(new MailAddress(mailTo.Email, mailTo.FullName));
                mailMessages.Add(mailMessage);
            }
            return(mailMessages);
        }