public JsonResult AddJudge(Fpp.Core.Models.JudgeDetails judgeDetails)
        {
            var uid = 0;
            if (judgeDetails.UserId <= 0)
            {
                User u = new User();
                u.Name = judgeDetails.Name;
                String[] str = u.Name.Split(' ');
                u.FirstName = str[0];
                u.LastName = "";
                if (str.Length > 1)
                {
                    for (int i = 1; i < str.Length; i++)
                    {
                        if (u.LastName.Length > 0) u.LastName += " ";
                        u.LastName += str[i];
                    }
                }

                u.EmailAddress = judgeDetails.Email;
                u.Mobile = judgeDetails.Mobile;

                u.Address = judgeDetails.Address;
                u.Postcode = judgeDetails.PostCode;
                u.Password = "******";
                uid = u.Create();
                u.AccountVerified();
            }
            else
            {
                uid = judgeDetails.UserId;
            }
            Judge j = new Judge(judgeDetails.JudgeId);
            j.ShowID = judgeDetails.ShowId;
            j.UserID = uid;
            j.JudgeName = judgeDetails.Name;
            j.Notes = judgeDetails.Notes;
            j.ShowDetailsID = judgeDetails.ShowDetailsId;
            j.Save();
            return Json(new
            {
                UserId = uid,
                JudgeId = j.ID,
                Status = 0
            });
        }
 public int Add(Fpp.Core.Models.TrophiesRosettes trophiesRosettes)
 {
     string sql = string.Format(@"insert INTO TrophiesRosettes  (ShowId, ShowDetailsId, ShowDate, ClsNo, ClassType, ClassName, Count, Trophies, Rosettes, EntryType, lho, AwardByHeight)
         values ({0}, {1}, '{7:yyyy-MM-dd}', {2}, {8}, '{3}', {4}, {5}, {6}, {9}, {10}, {11})",
         trophiesRosettes.ShowId,
         trophiesRosettes.ShowDetailsId,
         trophiesRosettes.ClsNo,
         trophiesRosettes.ClassName,
         trophiesRosettes.Count,
         trophiesRosettes.Trophies,
         trophiesRosettes.Rosettes,
         trophiesRosettes.ShowDate,
         (int)trophiesRosettes.ClassType,
         trophiesRosettes.EntryType,
         trophiesRosettes.Lho,
         trophiesRosettes.AwardByHeight);
     return RunInsert(sql);
 }
        public static void Add(int UserId, Fpp.Core.Models.UserCampingModel UserCamping)
        {
            String moduleSettings = ModuleConfig.GetSettings();
            Fpp.Data.Camping c = new Fpp.Data.Camping(moduleSettings);

            var nights = (UserCamping.CampingDays.Split(',').Length == 0) ? 1 : UserCamping.CampingDays.Split(',').Length;
            c.AddUserCamping(UserId, Core.Utils.HTMLToSqlQuote(UserCamping.PartyName), Core.Utils.HTMLToSqlQuote(UserCamping.Comments), UserCamping.CampingDays, nights, UserCamping.PitchSize);
        }
        public int Save(int ShowId, Fpp.Core.Models.DogsModel dog)
        {
            var currentClasses = GetDogsClasses(ShowId, dog.Id);
            _dogclasses.DeleteDog(dog.Id, ShowId);
            if (dog.ClassNo != null && dog.ClassNo.Any())
            {
                List<int> classes = (from item in dog.ClassNo
                                     select item.Id
                                   ).ToList();

                List<int> altHandlers = (from item in dog.ClassNo
                                         select item.AltHandler != null ? item.AltHandler.Id : -1
                                   ).ToList();

                List<int> ro = (from item in currentClasses
                                where item.DogID == dog.Id
                                select item.RO
                                ).ToList();

                return _dogclasses.Add(dog.Id, ShowId, classes, altHandlers, ro, dog.Lho);
            }
            else
            {
                return 0;
            }
        }
        public JsonResult MakePayment(Fpp.Core.Models.ShowEntry showEntry)
        {
            ProcessEntry.ProcessEntry processEntry = new ProcessEntry.ProcessEntry();
            TrackUser("AdminMakePayment", Newtonsoft.Json.JsonConvert.SerializeObject(showEntry), showEntry.UserId);

            return Json(new
            {
                Response = processEntry.AdminPayForShow(showEntry)
            });
        }
        public JsonResult Helper2Ring(Fpp.Core.Models.RPHelper RingHelper)
        {
            var helper = new Business.Helpers(RingHelper.HelperId);
            helper.updateRing(RingHelper.RingId);

            return Json(new
            {
                Status = 0
            });
        }
        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 JsonResult UserEnterShow(Fpp.Core.Models.UserPaymentDetails userPaymentDetails)
        {
            ProcessEntry.ProcessEntry processEntry = new ProcessEntry.ProcessEntry();
            userPaymentDetails.UserId = CurrentUser.ID;
            try
            {
                TrackUser("UserEnterShow", Newtonsoft.Json.JsonConvert.SerializeObject(userPaymentDetails));
            }
            catch
            {
                AppException.LogEvent(
                    $"UserEnterShow:UserId:{userPaymentDetails.UserId} ShowId{userPaymentDetails.ShowId}");
            }

            return Json(new
            {
                Status = processEntry.EnterShow(userPaymentDetails)
            });
        }
 public JsonResult CalcEntry(Fpp.Core.Models.UserShowEntry userShowEntry)
 {
     var process = new ProcessEntry.ProcessEntry();
     EntryDetails.SaveEntryv2(userShowEntry);
     process.CalcShow(userShowEntry);
     return Json(new
     {
         Status = 0
     });
 }
        public JsonResult UpdateAltHandler(Fpp.UI.Web.Models.AltHandlerModel altHandlerModel)
        {
            User u = new User(altHandlerModel.AltHandlerId);
            bool newAltHandler = true;
            if (u.UserID > -1)
            {
                newAltHandler = false;
            }
            u.Name = altHandlerModel.AltName;
            u.FirstName = "";
            u.LastName = "";
            u.EmailAddress = "";
            u.Password = "";
            u.Address = altHandlerModel.AltAddress;
            u.Postcode = altHandlerModel.AltPostcode;
            u.HomePhone = altHandlerModel.AltHomePhone;
            u.Mobile = altHandlerModel.AltMobile;
            u.Update();

            altHandlerModel.CurrentUserId = altHandlerModel.CurrentUserId > 0
                ? altHandlerModel.CurrentUserId
                : CurrentUser.ID;
            if (newAltHandler)
            {
                AltHandler.Add(altHandlerModel.CurrentUserId, u.UserID);
            }

            return Json(new
            {
                Status = 0,
                UserId = altHandlerModel.CurrentUserId,
                AltHandlersList = AltHandler.GetAllAltHandlersList(altHandlerModel.CurrentUserId)
            });
        }
 public JsonResult UpdateRingCls(Fpp.Core.Models.RPRingClassUpdate RingClassUpdate)
 {
     ShowClasses.UpdateRings(RingClassUpdate);
     ShowClasses.UpdateJudgeClasses(RingClassUpdate);
     return Json(new
     {
         Status = 0,
     });
 }
        public JsonResult SaveHandler(Fpp.Core.Dto.HandlerDetailsDto handlerDetails)
        {
            try
            {
                AuditManager.TrackUserEvent(handlerDetails.UserId, "SaveHandler", "");
            }
            catch
            {
            }

            bool validUser = false;
            bool newUser = false;
            User u;
            if (handlerDetails.UserId > 0)
            {
                u = new User(handlerDetails.UserId);
                validUser = true;
            }
            else
            {
                if (!handlerDetails.IsAdmin)
                {
                    u = new User(CurrentUser.UserID);
                    validUser = true;
                }
                else
                {
                    //
                    // if a blank email address, then just accept it and create a
                    // new blank user
                    //
                    if (string.IsNullOrEmpty(handlerDetails.Email))
                    {
                        validUser = true;
                        newUser = true;
                        u = new User();
                    }
                    else
                    {

                        u = new User(handlerDetails.Email);
                        if (u.UserID > 0)
                        {
                            AppException.LogError("email exists(SH)");
                            return Json(new
                            {
                                Status = 1,
                                Message = "They was an issue saving your details (SH)"
                            });
                        }
                        else
                        {
                            validUser = true;
                            newUser = true;
                        }
                    }
                }
            }
            if (validUser)
            {
                u.Name = handlerDetails.Name;
                u.FirstName = "";
                u.LastName = "";
                String[] nameSplit = u.Name.Split(' ');
                if (nameSplit.Length > 0) u.FirstName = nameSplit[0];
                if (nameSplit.Length > 1) u.LastName = nameSplit[1];
                if (nameSplit.Length > 2) u.LastName += nameSplit[2];
                if (nameSplit.Length > 3) u.LastName += nameSplit[3];

                u.EmailAddress = handlerDetails.Email;
                u.Address = handlerDetails.Address;
                u.Postcode = handlerDetails.Postcode;
                u.HomePhone = handlerDetails.HomePhone;
                u.Mobile = handlerDetails.Mobile;
                u.Password = handlerDetails.Password;
                if (newUser)
                {
                    u.Password = "******";
                }
                u.Update();
                if (newUser)
                {
                    u.AccountVerified();
                }
            }

            return Json(new
            {
                Status = 0,
                u.UserID
            });
        }
        public JsonResult SaveEntry(Fpp.Core.Models.UserShowEntry userShowEntry)
        {
            userShowEntry.UserId = CurrentUser.ID;
            try
            {
                TrackUser("SaveEntry", Newtonsoft.Json.JsonConvert.SerializeObject(userShowEntry));
                EntryDetails.SaveEntryv2(userShowEntry);

            }
            catch
            {
                AppException.LogEvent(
                    $"SaveEntry:UserId:{userShowEntry.UserId} ShowId{userShowEntry.ShowId} error logging entry");
            }
            return Json(new
            {
                Status = 0
            });
        }
        public static UserShows SaveEntry(HttpContext context, String data, Fpp.WebModules.Business.User currentUser, Shows thisShow)
        {
            DogClasses dc = new DogClasses();
            int handlertype = Convert.ToInt32(context.Request["handlertype"]);
            String[] dogs = data.Split(',');
            String[] altHandlersList = context.Request["althandlerslist"].Split(',');
            int waitingList = Convert.ToInt32(context.Request["waitinglist"]);

            //
            //  Multidog format is packed as
            //  <dogid>@<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>][,<dogid>#<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>]]
            //
            MultiDog.DeleteUserFromShow(currentUser.ID, thisShow.ID);
            String[] pairTeams = context.Request["pairteams"].Split(',');
            if (!String.IsNullOrEmpty(context.Request["pairteams"])) {
                foreach (String pairTeam in pairTeams)
                {
                    String[] pt = pairTeam.Split(';');
                    int DogID = -1;
                    int ClsID = -1; ;

                    foreach (String p in pt)
                    {
                        String[] dogcls;
                        String[] otherHandlerDog;
                        if (p.IndexOf(':') > 0)
                        {
                            dogcls = p.Split(':')[0].Split('@');
                            DogID = Convert.ToInt32(dogcls[0]);
                            ClsID = Convert.ToInt32(dogcls[1]);
                            otherHandlerDog = p.Split(':')[1].Split('.');

                            String []handlerDetails = otherHandlerDog[0].Split('-');
                            if (handlerDetails.Length > 1)
                            {
                                String handlerName = handlerDetails[0];
                                int handlerID = -1;
                                int.TryParse(handlerDetails[1], out handlerID);

                                String[] dogDetails = otherHandlerDog[1].Split('-');
                                String dogName = dogDetails[0];
                                int dogID = -1;
                                int.TryParse(dogDetails[1], out  dogID );

                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, handlerName, dogName, handlerID, dogID);
                            }
                            else
                            {
                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, otherHandlerDog[0], otherHandlerDog[1]);
                            }
                        }
                        else
                        {
                            otherHandlerDog = p.Split('.');
                            String[] handlerDetails = otherHandlerDog[0].Split('-');
                            if (handlerDetails.Length > 1)
                            {
                                String handlerName = handlerDetails[0];
                                int handlerID = -1;
                                int.TryParse(handlerDetails[1], out handlerID);

                                String[] dogDetails = otherHandlerDog[1].Split('-');
                                String dogName = dogDetails[0];
                                int dogID = -1;
                                int.TryParse(dogDetails[1], out  dogID);

                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, handlerName, dogName, handlerID, dogID);
                            }
                        }
                    }
                }
            }

            foreach (String dog in dogs)
            {
                String[] details = dog.Split(':');
                int dogid = Convert.ToInt32(details[0]);

                String[] clslist = details[1].Split('.');
                List<int> classes = new List<int>();
                List<int> altHandlers = new List<int>();
                foreach (String clsid in clslist)
                {
                    if (clsid.Length > 0)
                    {
                        int altid = 0;
                        classes.Add(Convert.ToInt32(clsid));
                        for (int ii = 0; ii < altHandlersList.Length; ii++)
                        {
                            String[] kvPairs = altHandlersList[ii].Split(':');
                            if (kvPairs[0] == clsid && kvPairs[2] == details[0])
                            {
                                altid = Convert.ToInt32(kvPairs[1]);
                            }
                        }
                        altHandlers.Add(altid);
                    }
                }
                dc.Save(dogid, thisShow.ID, classes, altHandlers);
            }

            UserShows us = new UserShows(currentUser.ID, thisShow.ID);
            us.Status = us.Status = (int)UserShows.UserStatus.STATUS_SAVED ;

            //
            // add check to see if this person is on the judging list.
            if (Judge.isJudgeAtShow(currentUser.ID, thisShow.ID))
            {
                us.HandlerType = (int)UserShows.HandlerTypes.JUDGE;
            }
            else
            {
                us.HandlerType = handlertype;
            }
            if ( !String.IsNullOrEmpty(context.Request["optout"] )  ) {
                us.Optout = Convert.ToInt32(context.Request["optout"]);
            }
            us.Save();

            Camping camping = new Camping(thisShow.ID);
            if (camping.ID > -1)
            {
                String campParty = "";
                String campDays = "";
                String campComments = "";
                if (!String.IsNullOrEmpty(context.Request["campingdays"])) campDays = context.Request["campingdays"];
                if (!String.IsNullOrEmpty(context.Request["campingparty"])) campParty = context.Request["campingparty"];
                if (!String.IsNullOrEmpty(context.Request["campcomments"])) campComments = context.Request["campcomments"];
                if (campDays.Length > 0)
                {
                    UserCamping.Add(us.ID, campParty, campComments, campDays);
                }
            }

            if (waitingList == 1)
            {
                WaitingList.Add(us.ShowID, us.Userid);

            }

            return us;
        }
        public static void UpdateJudgeClasses(Fpp.Core.Models.RPRingClassUpdate RingClassUpdate)
        {
            String moduleSettings = ModuleConfig.GetSettings();
            Fpp.Data.ShowClasses sc = new Fpp.Data.ShowClasses(moduleSettings);

            sc.updateJudgeClasses(RingClassUpdate.JudgeClass.ClassId, RingClassUpdate.JudgeClass.JudgeId);
        }
        public JsonResult EnterShow(Fpp.Core.Models.UserShowEntry adminShowEntry)
        {
            ProcessEntry.ProcessEntry processEntry = new ProcessEntry.ProcessEntry();
            TrackUser("AdminEnterShow", Newtonsoft.Json.JsonConvert.SerializeObject(adminShowEntry),
                adminShowEntry.UserId);
            var response = processEntry.AdminEnteredShow(adminShowEntry);

            return Json(new
            {
                Response = response
            });
        }
 public static void UpdateRings(Fpp.Core.Models.RPRingClassUpdate RingClassUpdate)
 {
     foreach (var Ring in RingClassUpdate.Rings)
     {
         if (Ring.Classes != null)
         {
             int pos = 1;
             foreach (int ClsId in Ring.Classes)
             {
                 ShowClasses sc = new ShowClasses(ClsId);
                 sc.Position = pos++;
                 sc.RingID = Ring.Id;
                 sc.Update();
             }
         }
     }
 }
        public StatusCls CalcShow(Fpp.Core.Models.UserShowEntry showEntry)
        {
            DogClasses dc = new DogClasses();
            Shows show = new Shows(showEntry.ShowId);
            User currentUser = new User(showEntry.UserId);
            UserShows us = new UserShows(showEntry.UserId, showEntry.ShowId);

            decimal discountTotal = 0;
            var singleEntryId = getSingleEntry(showEntry.ShowId);

            //            Decimal amount = calcNewTotalForEntry(showEntry.ShowId, showEntry.UserId, singleEntryId, ref discountTotal, ref addNewTransaction);
            var showTransactions = Transaction.getTransactionForShowUser(us.ID.ToString("000000"));
            decimal fixedFees = 0M;

            var showEntries = DogClasses.calcCostOfEntry(showEntry.ShowId, showEntry.UserId);

            var entryCost = showEntries.Sum(x => x.Total);
            var noOfSingleEntries = showEntries.FirstOrDefault(x => x.ChargeTypeId == singleEntryId);

            var entriesDiscount = Math.Abs(ShowDiscounts.getDiscountFor(showEntry.ShowId, showEntry.UserId, "entry", (noOfSingleEntries != null ? noOfSingleEntries.Count : 0), showEntries).Amount);
            discountTotal = entriesDiscount;
            var currentEntryCost = (entryCost - entriesDiscount);
            if (!ShowDiscounts.discount100Percent(showEntry.ShowId, showEntry.UserId, "entry") && currentEntryCost > 0)
            {
                fixedFees = ShowDiscounts.getDiscountsByType(showEntry.ShowId, -1, (int)DiscountTypes.TransactionCharge).Sum(x => x.Amount);
                currentEntryCost += fixedFees;
            }

            var uc = new UserCamping(us.ID);
            if (uc.ID > -1)
            {
                var showCamping = new Camping(showEntry.ShowId);
                var campingCost = Camping.costOfEntry(showEntry.ShowId, showEntry.UserId);
                var campingDiscount = ShowDiscounts.getDiscountFor(showEntry.ShowId, showEntry.UserId, "camping", uc.Nights, null, campingCost);
                var discount = 0M;
                switch (campingDiscount.Type)
                {
                    case (int)CHARGES_SUBTYPES.percentCamping:
                        currentEntryCost = currentEntryCost - (campingCost - campingDiscount.Amount);
                        discountTotal += campingDiscount.Amount;
                        break;
                    case (int)CHARGES_SUBTYPES.n_NightsCamping:
                        if (campingDiscount.Amount == showCamping.Nights)
                        {
                            currentEntryCost = currentEntryCost + (campingCost - (showCamping.Costpershow));
                            discount = showCamping.Costpershow;
                        }
                        else
                        {
                            currentEntryCost = currentEntryCost + (campingCost - (campingDiscount.Amount * showCamping.Costpernight));
                            discount = campingDiscount.Amount * showCamping.Costpernight;
                        }
                        discountTotal += discount;
                        break;
                    default:
                        break;

                }

            }

            Decimal previousEntryCost = showTransactions
                            .Where(x => x.TransactionType == TransactionTypes.ShowEntry)
                            .Sum(x => x.Amount);
            Decimal whatHasBeenPaid = showTransactions
                            .Where(x => x.TransactionType == TransactionTypes.ShowEntryPayment)
                            .Sum(x => x.Amount);
            Decimal whatHasBeenRequested = showTransactions
                            .Where(x => x.TransactionType == TransactionTypes.RefundRequest)
                            .Sum(x => x.Amount);
            Decimal whatHasBeenRefund = showTransactions
                            .Where(x => x.TransactionType == TransactionTypes.RefundPaid || x.TransactionType == TransactionTypes.RefundCancelled)
                            .Sum(x => x.Amount);

            if (whatHasBeenPaid != 0)
            {
                if (Math.Abs(previousEntryCost) != currentEntryCost)
                {
                    currentEntryCost += fixedFees;
                }
            }
            StatusCls status = new StatusCls();
            status.PaymentSummary = CreatePaymentSummary(us);

            return status;
        }