public static void ChangeClasses(int showId, int userId, int dogId, int[] newClsIds)
        {
            AppException.LogEvent($"Change Classes Dog (UserId={userId}, DogId={dogId}) showid={showId}");
            try
            {
                var dc = new DogClasses(dogId, showId);
                dc.Save(dogId, showId, newClsIds.ToList(), null, dc.Lho);

                var us = new UserShows(userId, showId);
                var comms = new EmailManager();
                comms.SendEntryEmail(showId, userId, us.RefCode);

            }
            catch (Exception e)
            {
                AppException.LogError($"Error:ChangeClasses:{e.Message}, {e.StackTrace}");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var referrerURL = ConfigurationManager.AppSettings["ReferrerURL"];

            if (context.Request.UrlReferrer == null)
            {
                if (referrerURL != "")
                {
                    AppException.LogEvent(string.Format("UPG.Callback:UrlReferrer invalid {0} ", referrerURL));
                    context.Response.Write("success");
                    return;
                }
            }
            else if (context.Request.UrlReferrer.ToString() != referrerURL)
            {
                AppException.LogEvent(string.Format("UPG.Callback:UrlReferrer invalid {0} " ,referrerURL));
                context.Response.Write("success");
                return;
            }
            String ttt = context.Request.QueryString.ToString();

            AppException.LogEvent("FPMS:Callback:" + ttt);

            String item_number = getValue(ttt, "userrefno");
            String transactiontime = getValue(ttt, "transactiontime");
            String transactionnumber = getValue(ttt, "transactionnumber");
            String transactiontype = getValue(ttt, "transcationtype");
            String sh_reason = getValue(ttt, "sh_reason");
            String showentry = getValue(ttt, "showentry");

            if (transactionnumber == "-1")
            {
                String reason = getValue(ttt, "failurereason");
                AppException.LogEvent(string.Format("UPG.Callback:ProcessRequest:Card failed for {0}, reason:{1}"
                                , item_number, reason));
            }
            else
            {
                var currentEntryCost = 0M;
                try
                {
                    currentEntryCost = Convert.ToDecimal(showentry);
                }
                catch (Exception ex)
                {
                    AppException.LogEvent("UPG.Callback:ProcessRequest:" + ex.Message + "," + ex.StackTrace);
                }
                UserShows us = null;
                int itemNo = -1;
                try
                {
                    itemNo = Convert.ToInt32(item_number);
                    us = new UserShows(itemNo);
                }
                catch (Exception ex)
                {
                    AppException.LogEvent(string.Format("UPG.Callback:Getting UserShow Details({2}) :{0},{1}", ex.Message,ex.StackTrace, itemNo));
                }
                if (us != null)
                {
                    if (us.ID == itemNo) {
                        us.Status = (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID;
                        us.Save();

                        Transaction.Add(item_number, TransactionTypes.ShowEntryPayment, currentEntryCost, transactionnumber, us.ShowID, us.Userid, ConvertUGPDate(transactiontime));
                        AuditManager.TrackUserEvent(us.Userid, "Payment Received", string.Format("item no={0}", item_number));
                        try
                        {
                            var comms = new EmailManager();
                            comms.SendEntryEmail(us.ShowID, us.Userid, us.ID.ToString("000000"));
                        }
                        catch (Exception e)
                        {
                            AppException.LogEvent(string.Format("UPG.Callback:ProcessRequest: Failed sending payment confirmation. {0}", e.Message));
                            AuditManager.TrackUserEvent(us.Userid, "Payment Sending Email", string.Format("item no={0}", itemNo));
                        }
                    }
                    else
                    {
                        AuditManager.TrackUserEvent(us.Userid, "Payment Storage failure (us.Id != item_no)", string.Format("item no={0}", itemNo));
                    }
                }
                else
                {
                    AuditManager.TrackUserEvent(us.Userid, "Payment Failed", string.Format("item no={0}", item_number));
                }
            }
            context.Response.Write("success");
        }
 public JsonResult SendEMail(EmailMessage EmailMessage)
 {
     var mail = new EmailManager();;
     int status = 0;
     UserShows us = null;
     try
     {
         us = mail.SendMessage(EmailMessage);
     }
     catch (Exception e)
     {
         status = 1;
         if (e.Message == "NoEmail")
         {
             status = 2;
         }
     }
     return Json(new
     {
         Status = status,
         UserShowId = EmailMessage.UserShowId,
         ContactDate = (us != null ? us.ContactDate.ToString("dd-MMM hh:mm:ss") : ""),
         ContactStatus = (us != null ? us.ContactStatus : 0),
     });
 }
 public JsonResult SendBccEMail(EmailMessage EmailMessage)
 {
     var mail = new EmailManager();
     int status = 0;
     try
     {
         mail.Send("*****@*****.**", new MailMessage
         {
             Subject = EmailMessage.Subject,
             Body = EmailMessage.body
         });
     }
     catch (Exception e)
     {
         status = 1;
         if (e.Message == "NoEmail")
         {
             status = 2;
         }
     }
     return Json(new
     {
         Status = status,
     });
 }
        public StatusCls EnterShow(Fpp.Core.Models.UserPaymentDetails userPaymentDetails)
        {
            DogClasses dc = new DogClasses();
            Shows show = new Shows(userPaymentDetails.ShowId);
            User currentUser = new User(userPaymentDetails.UserId);
            UserShows us = new UserShows(userPaymentDetails.UserId, userPaymentDetails.ShowId);

            if (us.HandlerType == 1)
            {
                List<String> days = new List<string>();
                var tmp = ShowDetails.GetShowDaysForUser(userPaymentDetails.ShowId, userPaymentDetails.UserId);
                AppException.LogEvent(string.Format("Member({0}) Helpers.a:{1}", userPaymentDetails.UserId, tmp.Count));
                foreach (var t in tmp)
                {
                    // 24,Saturday,Scrimmer,1/2 AM,
                    var b = string.Format("{0},{1},{2},{3},{4}",
                        t.ID,
                        t.ShowDate.ToString("dddd"),
                        "Ring Party",
                        "All Day",
                        "-1",
                        -1);
                    days.Add(b);
                }
                AppException.LogEvent(string.Format("Member({0}) Helpers.b:{1}", userPaymentDetails.UserId, days.Count));
                HelperManager.AddHelper(userPaymentDetails.ShowId, userPaymentDetails.UserId, currentUser.Name, days.ToArray(), "");
            }

            String userRefNo = us.ID.ToString().PadLeft(6, '0');
            AppException.LogEvent(string.Format("Entry Details:{0} {1}, {2}, {3}, {4}",
                userRefNo, userPaymentDetails.EntryFee, userPaymentDetails.Total, userPaymentDetails.DiscountTotal, userPaymentDetails.TransactionFee));
            var showTransactions = Transaction.getTransactionForShowUser(userRefNo);
            var previousEntry = showTransactions.Where(x => x.TransactionType == TransactionTypes.ShowEntry).Sum(t => t.Amount);

            if (userPaymentDetails.EntryFee == Math.Abs(previousEntry))
            {
                    AppException.LogEvent(string.Format("****** Entry Entry fee == previousEntry ",
                        userRefNo, userPaymentDetails.EntryFee, userPaymentDetails.Total, userPaymentDetails.DiscountTotal, userPaymentDetails.TransactionFee));
            }

            if (userPaymentDetails.Total == 0 && userPaymentDetails.DiscountTotal >0 )
            {
                if (userPaymentDetails.EntryFee != Math.Abs( previousEntry ) )
                {
                    userPaymentDetails.EntryFee -= Math.Abs(previousEntry);
                    Transaction.Add(userRefNo, TransactionTypes.ShowEntry, -userPaymentDetails.EntryFee, "Entry Fee", us.ShowID, us.Userid, DateTime.Now);
                    if (userPaymentDetails.DiscountTotal > 0)
                    {
                        var discounts = showTransactions.Where(x => x.TransactionType == TransactionTypes.Discount).Sum(t => t.Amount);
                        userPaymentDetails.DiscountTotal -= discounts;
                        if (userPaymentDetails.DiscountTotal < 0) userPaymentDetails.DiscountTotal = 0;

                        Transaction.Add(userRefNo, TransactionTypes.Discount, userPaymentDetails.DiscountTotal, "Discount Applied", us.ShowID, us.Userid, DateTime.Now);
                    }
                    Transaction.Add(userRefNo, TransactionTypes.ShowEntryPayment, 0, "Entry Fee Paid", us.ShowID, us.Userid, DateTime.Now);
                }
            }
            else
            {
                if (userPaymentDetails.EntryFee != Math.Abs(previousEntry))
                {

                    if (userPaymentDetails.Total == 0)
                    {
                        userPaymentDetails.EntryFee -= Math.Abs(previousEntry);
                        Transaction.Add(userRefNo, TransactionTypes.ShowEntry, -userPaymentDetails.EntryFee, "Entry Fee", us.ShowID, us.Userid, DateTime.Now);
                        if (userPaymentDetails.DiscountTotal > 0)
                        {
                            var discounts = showTransactions.Where(x => x.TransactionType == TransactionTypes.Discount).Sum(t => t.Amount);
                            userPaymentDetails.DiscountTotal -= discounts;
                            if (userPaymentDetails.DiscountTotal < 0) userPaymentDetails.DiscountTotal = 0;

                            Transaction.Add(userRefNo, TransactionTypes.Discount, userPaymentDetails.DiscountTotal, "Discount Applied", us.ShowID, us.Userid, DateTime.Now);
                        }
                        Transaction.Add(userRefNo, TransactionTypes.ShowEntryPayment, 0, "Entry Fee Paid", us.ShowID, us.Userid, DateTime.Now);
                    }
                    else if (userPaymentDetails.Total > 0)
                    {
                        var lastShowEntry = showTransactions.OrderByDescending(t => t.TransactionDate).Take(2).ToList();
                        if (lastShowEntry.Any())
                        {
                            var transaction = lastShowEntry[0];
                            if (transaction != null && (transaction.TransactionType == TransactionTypes.TransactionCharge || transaction.TransactionType == TransactionTypes.ShowEntry))
                            {
                                Transaction.Delete(transaction.ID);
                                lastShowEntry.Remove(transaction);

                                if (lastShowEntry.Any())
                                {
                                    transaction = lastShowEntry[0];
                                    if (transaction != null && (transaction.TransactionType == TransactionTypes.ShowEntry || transaction.TransactionType == TransactionTypes.TransactionCharge))
                                    {
                                        Transaction.Delete(transaction.ID);
                                    }
                                }
                            }
                        }

                        Transaction.Add(userRefNo, TransactionTypes.ShowEntry, -userPaymentDetails.EntryFee, "Entry Fee", us.ShowID, us.Userid, DateTime.Now);
                        if (userPaymentDetails.TransactionFee != 0)
                        {
                            Transaction.Add(userRefNo, TransactionTypes.TransactionCharge, -userPaymentDetails.TransactionFee, "Transaction Fee", us.ShowID, us.Userid, DateTime.Now);
                        }
                        else
                        {
                            AppException.LogEvent(string.Format("No Transaction Fee {0}", userRefNo));
                        }
                        if (userPaymentDetails.DiscountTotal > 0)
                        {
                            Transaction.Add(userRefNo, TransactionTypes.Discount, userPaymentDetails.DiscountTotal, "Discount Applied", us.ShowID, us.Userid, DateTime.Now);
                        }
                    }
                    else
                    {
                        var refundRequests = showTransactions.Where(s => s.TransactionType == TransactionTypes.RefundRequest).Sum(t => t.Amount);
                        var refundsPaidOrCancelled = showTransactions.Where(s => s.TransactionType == TransactionTypes.RefundPaid || s.TransactionType == TransactionTypes.RefundCancelled).Sum(t => t.Amount);

                        var outstandingRefunds = refundRequests - refundsPaidOrCancelled;
                        Transaction.Add(userRefNo, TransactionTypes.RefundRequest, userPaymentDetails.Total - outstandingRefunds, "Refund Fee Requested", us.ShowID, us.Userid, DateTime.Now);
                        PendingRefunds.Add(us.ID, Math.Abs(userPaymentDetails.Total - outstandingRefunds), us.ShowID, us.Userid);
                        RefundForShow(us.ShowID, us.Userid);

                        if (userPaymentDetails.DiscountTotal > 0)
                        {
                            Transaction.Add(userRefNo, TransactionTypes.Discount, userPaymentDetails.DiscountTotal, "Discount Applied", us.ShowID, us.Userid, DateTime.Now);
                        }

                    }

                    var comms = new EmailManager();
                    if (userPaymentDetails.DiscountTotal == userPaymentDetails.EntryFee)
                    {
                        comms.SendEntryEmail(userPaymentDetails.ShowId, userPaymentDetails.UserId, userRefNo);
                    }
                    else
                    {
                        comms.SendSavedEmail(userPaymentDetails.ShowId, userPaymentDetails.UserId, userRefNo);
                    }
                }
            }
            StatusCls status = new StatusCls();
            status.UserID = currentUser.ID;
            status.Extra = createPaymentForm(currentUser, show, us.ID, userPaymentDetails.Total);    // currentUser, show, userRefNo, userPaymentDetails.Total);

            return status;
        }
 public void RefundForShow(int ShowId, int UserId)
 {
     var comms = new EmailManager();
     comms.SendForRefund(ShowId, UserId);
 }