public static StatusCls UpgradeDog(UpgradeDogView upgradeDogView)
        {
            var status = new StatusCls();
            AppException.LogEvent($"Upgrade Dog (UserID={upgradeDogView.UserId}, DogId={upgradeDogView.DogId})");
            try
            {
                DateTime activeDate;
                var currentUser = new User(upgradeDogView.UserId);
                var dog = new Dogs(upgradeDogView.DogId);
                DogHistory.Add(upgradeDogView);
                var mm = new MailMessage();
                var oldgrade = dog.Grade;
                if (upgradeDogView.UpgradeType == 0)
                {

                    mm.Subject = "First Place Processing - Confirmation of grade change";
                    var body = "This is a confirmation of grade change of your dog: " + dog.KCName + " from grade " + oldgrade + " to grade " + upgradeDogView.NewGrade +
                                  Environment.NewLine + Environment.NewLine +
                                  "Your dog will be grade " + upgradeDogView.NewGrade + " from the " + upgradeDogView.WinDate.AddDays(25).ToString("dd MMM yyyy") +
                                  Environment.NewLine + Environment.NewLine;
                    mm.Body = body;
                    activeDate = upgradeDogView.WinDate.Add(new TimeSpan(25, 0, 0, 0));
                }
                else
                {
                    mm.Subject = "First Place Processing - Confirmation of grade change";
                    var body = "This is a confirmation of grade change of your dog: " + dog.KCName + " from grade " + oldgrade + " to grade " + upgradeDogView.NewGrade + Environment.NewLine + Environment.NewLine;
                    mm.Body = body;
                    activeDate = DateTime.Now;
                }
                EmailManager.Send(currentUser, mm);
                if (activeDate > DateTime.Now)
                {
                    status.Extra = activeDate.ToString("dd MMM yyyy");
                }
            }
            catch (Exception e)
            {
                AppException.LogEvent($"Error:UpgradeDog:{e.Message} {e.StackTrace}");
            }
            return status;
        }
        public JsonResult CancelShow(int ShowId)
        {
            StatusCls status = new StatusCls();
            if (CurrentUser != null)
            {
                Fpp.Domain.CancelEntry.Cancel(CurrentUser, new Shows(ShowId));

                status.Status = 0;
                status.UserID = CurrentUser.ID;

            }
            else
            {
                status.Status = 10;
            }
            return Json(new
            {
                status
            });
        }
        public JsonResult SendBulkEmailMessage(EmailMessage bulkEmailMessage)
        {
            StatusCls status = new StatusCls();

            status.ClsID = bulkEmailMessage.UserShowId;
            UserShows us = new UserShows(bulkEmailMessage.UserShowId);
            User user = new User(us.Userid);

            if (user.EmailAddress.Length > 5)
            {
                Shows show = new Shows(us.ShowID);

                MailMessage mm = new MailMessage();

                AlternateView plainView = AlternateView.CreateAlternateViewFromString(bulkEmailMessage.body, null, MediaTypeNames.Text.Plain);
                mm.Body = bulkEmailMessage.body;

                SmtpClient client = new SmtpClient();
                mm.From = new MailAddress("*****@*****.**", "First Place Processing");
                mm.To.Add(new MailAddress(user.EmailAddress, user.Name));
                mm.Subject = bulkEmailMessage.Subject;
                client.Send(mm);

                us.ContactStatus = 1;
                us.ContactDate = DateTime.Now;
                us.SaveContactDetails();
                status.Data = us.ContactDate.ToString("dd-MMM hh:mm:ss");
                status.DogID = us.ContactStatus;
            }
            else
            {
                status.Status = 2;
            }
            return Json(new
            {
                status
            });
        }
        public StatusCls GetEntryForm(int ShowId, int UserId, int handlerType)
        {
            StatusCls status = new StatusCls {
                MultiDogClasses = new List<MultiDogClasses>()
            };
            Shows thisShow = new Shows(ShowId);
            User currentUser = new User(UserId);
            List<ShowClasses> classList = ShowClasses.GetAllClassesForShow(ShowId).Where(sc => sc.Part == 0).ToList();
            var lhoLabel = false;
            var fouthHeightLabel = false;
            if (classList.Any(x => x.Lho > 0))
            {
                lhoLabel = true;
                if (classList.Any(x => x.Lho == 3))
                {
                    lhoLabel = false;
                    fouthHeightLabel = true;
                }
            }

            status.MultiDogClasses = TeamPairsManager.GetTeamPairClasses(ShowId);

            UserShows us = new UserShows(UserId, ShowId);
            //
            // if user entering a new show then set up the handler type, cos that is pasted in
            if (us.ID == -1)
            {
                us.HandlerType = handlerType;
            }
            //
            // add check to see if this person is on the judging list.
            // and there are not a member as members override the judging discounts.
            if (Judge.isJudgeAtShow(UserId, ShowId) && handlerType == 0)
            {
                handlerType = 2;
                us.HandlerType = 2;
            }
            else
            {
                //
                // check if alt handlers are judging
                //
                List<AltHandler> altHList = AltHandler.GetAllAltHandlersList(us.Userid);
                foreach (AltHandler alt in altHList)
                {
                    if (Judge.isJudgeAtShow(alt.AltHandlerID, ShowId))
                    {
                        handlerType = 2;
                        us.HandlerType = 2;
                    }
                }
            }

            Dogs dog = new Dogs();
            List<Dogs> dogs = Dogs.GetAllDogsForHandler(UserId, thisShow.ShowDate);

            String html = $"<input type='hidden' name='handlertype' id='handlertype' value='{us.HandlerType}' />";
            String header = "<div class='dogRow group header'><div class='petName header'>&nbsp;</div>";
            Boolean headerCompleted = false;
            String rowClass = "dogRowAlt";
            foreach (Dogs d in dogs.Where(d => d.Grade > 0 ) )
            {
                String buttons = "";
                DogClasses dc = new DogClasses(d.ID);
                dc.getDogsClasses(ShowId);
                if (d.Grade != 0)
                {
                    buttons = "<div class='buttons'><a href='#tick'><img title='Select All Single Classes' class='tickcross tickimg' src='/Content/Assets/tickv2.png' /></a><a href='#cross'><img title='Clear All Classes' class='tickcross crossimg' src='/Content/Assets/crossv1.png' /></a>";
                    buttons += "</div>";
                    if (lhoLabel)
                    {
                        buttons += @"<div class='lho'><label for='cklho_" + d.ID + "'>Lower height<input type='checkbox' value='1' id='cklho_" + d.ID + "' " + (dc.Lho == 1 ? "checked='checked'" : "") + "   /></label></div>";
                    }
                    if (fouthHeightLabel)
                    {
                        buttons += @"<div class='ext'><label for='cklho_" + d.ID + "'>4th height<input type='checkbox' value='1' id='cklho_" + d.ID + "' " + (dc.Lho == 1 ? "checked='checked'" : "") + "   /></label></div>";
                    }
                    buttons += "<div class='infoText'>Handler:</div>";
                    if (d.AltHandlerID == -1)
                    {
                        buttons += currentUser.Name;
                    }
                    else
                    {
                        User altHandler = new User(d.AltHandlerID);
                        buttons += altHandler.Name;
                    }
                }
                html += String.Format("<div class='{2} group themeBorder-t' dogid='{0}' grade='{4}'><div class='petName'><div class='lbl'>{1}<p class='grade'>{4}</p></div>{3}</div>", d.ID, d.PetName, rowClass, buttons, d.DisplayGrade);
                rowClass = (rowClass == "dogRowAlt" ? "dogRow" : "dogRowAlt");

                String classTable = "";
                String dayName = "";
                String lastDay = "";
                Boolean classesForDog = true;
                foreach (ShowClasses cls in classList)
                {
                    if (dayName != cls.Showdate.ToString("dddd, dd MMM"))
                    {

                        if (dayName != "")
                        {
                            if (!classesForDog)
                            {
                                classTable += String.Format("<div class='clsNo' ><span class='naCls'>n/a</span></div>");
                            }
                            classTable += "</div>";
                        }
                        classesForDog = false;
                        lastDay = dayName;
                        dayName = cls.Showdate.ToString("dddd, dd MMM");

                        ShowDetails showDetails = new ShowDetails(cls.ShowDetailsID);
                        classTable += String.Format("<div class='day' classlimit='{0}'>", showDetails.ClassLimit);

                        if (!headerCompleted)
                        {
                            header += String.Format("<div class='day header' >{0}</div>", dayName);
                        }
                    }

                    //
                    //  cls.EntryType == (int)EntryType.EntryTypes.ABC &&
                    //

                    if (isDogInClass(cls, d))
                    {
                        int otherDogs = 0;
                        int reserves = 0;
                        bool teamName = false;
                        String ticked = "";
                        String altHandlerInfo = "<img class='handler' src='/Content/Assets/AddHandler.png'  width='16' height='14' />";
                        int clsIndex = dc.Classlist.IndexOf(cls.ID);
                        if (clsIndex > -1)
                        {
                            ticked = "tick";
                            if (dc.AltHandlerList[clsIndex] > 0)
                            {
                                User u = new User(dc.AltHandlerList[clsIndex]);
                                altHandlerInfo = "<img class='handler changed' width='16' height='14' src='/Content/Assets/AddHandler.png' data-althandlerid='" + dc.AltHandlerList[clsIndex].ToString() + "' title='Handler:" + u.Name + "' />";
                            }
                        }
                        classesForDog = true;

                        if (otherDogs > 0)
                        {
                            String iconType = "mdSet.png";
                            var multiDogs = "";
                            classTable += String.Format("<div {12} {13} {14} {15} class='clsNo " + ticked + "' classno='{15}' classcount='{11}' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' otherdogs='{5}' reserves='{9}' team='{10}' ><span class='chghandlemenu'>[+]</span>{6}<a class='otherdogs' title='Enter other dogs'><img src='/Content/Assets/{8}' >{7}</img></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='ah'>*</span><span class='clsname'>{1}</span></span></div>",
                                cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType,
                                otherDogs, altHandlerInfo, multiDogs, iconType, reserves, teamName, cls.ClassCount,
                                cls.Anysize == 1 ? "anysize" : "", cls.Veteran == 1 ? "veteran" : "",  ShowLhoModifier( cls.Lho ), cls.ClassNo, cls.AwardByHeight > 0 ? "AH" : "");

                        }
                        else
                        {
                            if (cls.EntryType == 10)
                            {
                                var hasChampDogsIcon = "mdNotSet.png";
                                var allDetailsCheck = 0;

                                var wins = DogHistory.GetRecordedWins(d.ID);
                                var h = "<span class='wins'>";
                                foreach (var dogH in wins) {
                                    h += string.Format("<span class='champ-wins' data-upgradetype='{4}'  data-winid='{3}'  data-showname='{0}' data-showdate='{1:dd-MM-yy}' data-showclass='{2}'></span>",
                                        dogH.ShowName, dogH.DateOfWin, dogH.ClassWon, dogH.Id, dogH.UpgradeType);
                                    allDetailsCheck += (dogH.ShowName.Length > 0 && dogH.ClassWon.Length > 0) ? 1 : 0;
                                }
                                if (allDetailsCheck == 4)
                                {
                                    hasChampDogsIcon = "mdSet.png";
                                }
                                h += "</span>";
                                classTable += String.Format("<div class='clsNo " + ticked + "' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' classCount='{8}'><span class='chghandlemenu'>[+]</span>{5}<a class='champ-dogs " + (allDetailsCheck == 4 ? " all-wins-entered " : "") + "' href='' title='Enter Your Wins' ><img src='/Content/Assets/{6}' /></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='clsname'>{1}</span></span>{7}</div>",
                                    cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType, altHandlerInfo, hasChampDogsIcon, h, cls.ClassCount);
                            }
                            else if (cls.EntryType == 11)
                            {
                                var hasJuniorDetails = "mdNotSet.png";
                                var allDetailsCheck = false;

                                var jnr= new Juniors(cls.ID, d.ID);
                                var h = "";
                                if (jnr != null && jnr.ID > 0)
                                {
                                    h += string.Format("<span class='junior-details' data-id='{2}' data-dob='{0:dd-MM-yyyy}' data-ykcnumber='{1}'></span>",
                                                jnr.DoB, jnr.YKCNumber, jnr.ID);
                                    hasJuniorDetails = "mdSet.png";
                                    allDetailsCheck = true;
                                }
                                h += "";
                                classTable += String.Format("<div {9} {10} {11} {12} class='clsNo " + ticked + "' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' classCount='{8}'  ><span class='chghandlemenu'>[+]</span>{5}<a class='ykc " + (allDetailsCheck  ? " all-entered " : "") + "' href='' title='Enter YKC Details' ><img src='/Content/Assets/{6}' /></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='ah'>*</span><span class='clsname'>{1}</span></span>{7}</div>",
                                    cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType, altHandlerInfo,
                                    hasJuniorDetails, h, cls.ClassCount, cls.Anysize == 1 ? "anysize" : "", cls.Veteran == 1 ? "veteran" : "", ShowLhoModifier(cls.Lho), cls.AwardByHeight > 0 ? "AH" : "");
                            }
                            else
                            {
                                //                                lhoclass = (cls.Lho == 0 && dc.Lho == 1 ? " hidecls ": "");

                                var lhoclass = "";
                                if (cls.Lho == 0 )
                                {
                                    lhoclass = (dc.Lho == 1 ? " hidecls " : "");
                                }
                                else
                                {
                                    if (cls.Lho < 3)
                                    {
                                        lhoclass = ""; // (dc.Lho == 1 ? "" : " hidecls ");
                                    }
                                    else
                                    {
                                        lhoclass = (dc.Lho == 0 ? " hidecls " : "");
                                    }

                                }

                                classTable += String.Format("<div {7} {8} {9} {10}  class='clsNo " + ticked + " " + lhoclass + "' clsid='{0}' chargeType='{2}' classType='{3}' entryType='{4}' classCount='{6}'><span class='chghandlemenu'>[+]</span>{5}<a class='nootherdogs'><img class='nootherdogs' src='/Content/Assets/infov1.png' /></a><span class='clickable'><img class='tickHolder ' src='/Content/Assets/tickv2.png' /><span class='ah'>*</span><span class='clsname'>{1}</span></span></div>",
                                    cls.ID, ShortenName(cls), cls.ChargeType, cls.ClassType, cls.EntryType, altHandlerInfo, cls.ClassCount, cls.Anysize == 1 ? "anysize" : "", cls.Veteran == 1 ? "veteran" : "", ShowLhoModifier(cls.Lho), cls.AwardByHeight > 0 ? "AH" : "");
                            }
                        }
                    }
                }

                headerCompleted = true;
                if (!classesForDog)
                {
                    classTable += String.Format("<div class='clsNo nohover'><span class='naCls'>n/a</span></div>");
                }
                html += classTable + "</div>";
                html += "</div>";
            }

            header += "</div>";

            String showDetailsBox = "";
            showDetailsBox += "<div class='showDetails themeText'>";
            showDetailsBox += "<div class='title'  style=' width: 375px;white-space: nowrap;overflow: hidden;text-overflow: clip;'>" + thisShow.ShowName + "</div>";
            showDetailsBox += "<div class='showdate'>" + thisShow.ShowDate.ToString("dd MMM yyyy") + "</div>";
            showDetailsBox += "</div >";

            showDetailsBox += "<div class='helpBox themeNoticeText themeBorder'>";
            showDetailsBox += "<div><span class='legend themeBackgroundColor'>Help Information</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/tickv2.png' /><span class='afterImgAdj'> To select all classes</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/crossv1.png' /><span class='afterImgAdj'>  To unselect all classes</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/mdNotSet.png' /><span class='afterImgAdj'>  Missing details</span></div>";
            showDetailsBox += "<div><img src='/Content/Assets/mdSet.png' /><span class='afterImgAdj'> All detail entered</span></div>";
            showDetailsBox += "<div><span style='color:#fff;'>[+]</span><span ><span> To Add Handler</span></div>";
            showDetailsBox += "<div><span class='ah' style='color:#fff;display:inline;margin: 0px 7px;top:4px'>*</span><span ><span>Awards By Height</span></div>";
            showDetailsBox += "</div>";

            String totalsBox = "";
            totalsBox += "<div class='totals themeBorder' ><div class='showTotals short themeBackgroundColor themeBorder'>";
            totalsBox += "<div class='clsTypeRow group fulltotal'>";
            totalsBox += "<div class='clsTypePaymentInfo themeBorder-t'></div>";
            totalsBox += "<div class='clsTypeTotal themeBorder-t themeBorder-l'>0.00</div>";
            totalsBox += "</div >";
            totalsBox += "</div>";
            totalsBox += "<div class='ctrlButtons'>";

            if (thisShow.Status == (int)Shows.SHOW_STATUS.PUBLISHED)
            {
                if (us.Status != (int)UserShows.UserStatus.STATUS_ENTERED_NOT_PAID
                    && us.Status != (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID)
                {
                    totalsBox += "<input type='button' id='btnSaveEntry' value='Save Details' />";
                }
            }

            HttpCookie cookie = HttpContext.Current.Request.Cookies[".FPPAUTH"];
            if (cookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

                String[] lists = ticket.UserData.Split(':');
                int userid = Convert.ToInt32(lists[1]);
                if ((lists[0].Contains("showadmin") && thisShow.Status == (int)Shows.SHOW_STATUS.NOT_PUBLISHED)
                    || thisShow.Status == (int)Shows.SHOW_STATUS.PUBLISHED)
                {
                    totalsBox += "<input type='button' id='btnDoEntry' value='Enter Show' />";
                }
            }

            totalsBox += "<input type='button' id='btnCancel' value='Close' /></div>";
            totalsBox += "</div >";
            status.Status = 0;
            status.UserID = currentUser.ID;
            status.Data = "<input id='ShowID' type='hidden' value='" + ShowId.ToString() + "' /><div class='enterform themeBorder' showid='" + ShowId.ToString() + "'><div class='vscroll'>" + header + "<div class='hscroll'>" + html + "</div></div></div>" + showDetailsBox + totalsBox;
            status.Extra = AltHandler.GetAllAltHandlers(UserId);

            status.TransactionSummaryData = TransactionSummary.getTransactionSummary(ShowId, currentUser.ID);

            status.Camping = new Camping(ShowId);
            status.CampingSummary = UserCamping.GetCampingSummary(ShowId, 0);
            if (!status.CampingSummary.Any())
            {
                for (DateTime dt = status.Camping.Startdate; dt <= status.Camping.Enddate; dt = dt.AddDays(1))
                {
                    status.CampingSummary.Add(new Core.Dto.CampingSummary
                    {
                        CampingDay = dt,
                        Count = 0
                    });
                }
            }
            else
            {
                status.CampingFull = status.CampingSummary.Where(x => x.Count >= status.Camping.Limit).Count() == status.CampingSummary.Count();
            }
            status.PaymentSummary = CreatePaymentSummary(us, false, status.CampingFull);
            if (status.Camping.ID > -1 && !status.CampingFull)
            {
                status.UserCamping = new UserCamping(us.ID);
            }
            status.UserShow = us;

            status.MultiDogEntries = TeamPairsManager.GetTeamPairs(ShowId, UserId, status.MultiDogClasses);

            status.Lho = lhoLabel;
            status.fouthHeight = fouthHeightLabel;

            return status;
        }
        public StatusCls CreateShow(int orgId, string showName, string ShowDate, int srcId, string closingDate)
        {
            var status = new StatusCls();
            var shows = new Shows();
            status.ShowID = shows.AddShow(orgId, showName, ShowDate);
            var newShow = new Shows(status.ShowID);
            if (!string.IsNullOrEmpty( closingDate ))
            {
                newShow.ClosingDate = DateTime.Parse(closingDate);
                newShow.Save();
            }

            var showDetails = new ShowDetails();
            if (srcId == -1)
            {
                showDetails.AddDay(DateTime.Parse(ShowDate), status.ShowID, 3);
                ShowCharges[] ShowChargesList = {
                                ShowCharges.CreateCharge("Single Entry", 3.00M, status.ShowID),
                                ShowCharges.CreateCharge("Vegas Money", 4.00M, status.ShowID),
                                ShowCharges.CreateCharge("Pairs", 5M, status.ShowID),
                                ShowCharges.CreateCharge("Team", 10M, status.ShowID)
                            };

                ClassTypes.CreateClassType("Agility", "Ag", EntryTypes.Standard, 1, ShowChargesList[0].ID, status.ShowID);
                ClassTypes.CreateClassType("Jumping", "Jmp", EntryTypes.Standard, 1, ShowChargesList[0].ID, status.ShowID);
                ClassTypes.CreateClassType("Money Class", "Money", EntryTypes.Standard, 1, ShowChargesList[1].ID, status.ShowID);
                ClassTypes.CreateClassType("Team", "Tms", EntryTypes.Team, 1, ShowChargesList[3].ID, status.ShowID);
                ClassTypes.CreateClassType("Pairs", "Prs", EntryTypes.Pairs, 1, ShowChargesList[2].ID, status.ShowID);
                ClassTypes.CreateClassType("Veterans", "Vets", EntryTypes.Veterans, 1, ShowChargesList[0].ID, status.ShowID);
                ClassTypes.CreateClassType("Anysize", "Any", EntryTypes.Veterans, 1, ShowChargesList[0].ID, status.ShowID);

                ShowDiscounts.CreateDiscount(DiscountTypes.Member, 5, 5, DateTime.Now, "", ShowChargesList[0].ID, status.ShowID);
                ShowDiscounts.CreateDiscount(DiscountTypes.Member, 4, 2, DateTime.Now, "", 0, status.ShowID);
                ShowDiscounts.CreateDiscount(DiscountTypes.Judge, 5, 5, DateTime.Now, "", ShowChargesList[0].ID, status.ShowID);
                ShowDiscounts.CreateDiscount(DiscountTypes.Judge, 4, 1, DateTime.Now, "", 0, status.ShowID);
                ShowDiscounts.CreateDiscount(DiscountTypes.Fixed, 1, 2.75M, DateTime.Now, "", 0, status.ShowID);
                ShowDiscounts.CreateDiscount(DiscountTypes.TransactionCharge, 1, 0.5M, DateTime.Now, "", 0, status.ShowID);
            }
            else
            {
                var showChargeMap = CreateShowChargeMap(srcId, status.ShowID);
                var classTypesMap = CreateClassTypes(srcId, status.ShowID, showChargeMap);
                var showDiscountMap = CreateDiscountTypes(srcId, status.ShowID, showChargeMap);

                //List<ClassTypes> srcClassTypesList = ClassTypes.GetClassTypesForShow(srcid);
                //List<ShowDiscounts> srcShowDiscountsList = ShowDiscounts.getClassChargeDetails(srcid);
                List<ShowDetails> srcShowDaysList = ShowDetails.GetShowDetails(srcId);

                //DateTime lastShowDate = Convert.ToDateTime(context.Request["lastshowdate"]);
                //lastShowDate = lastShowDate.AddDays(1);
                //ShowDetails sd = new ShowDetails(ShowDetailsID);

                //status.ShowDetailsID = sd.Copy(lastShowDate);
                var showDate = DateTime.Parse(ShowDate);
                foreach (ShowDetails showDay in srcShowDaysList)
                {
                    showDetails.AddDay(showDate, status.ShowID, 3);
                    ShowClasses showClass = new ShowClasses();
                    showClass.BulkCopy(srcId, showDay.ID, showDetails.ID, showChargeMap, classTypesMap, status.ShowID);
                    showDate = showDate.AddDays(1);
                }
                ShowDiscounts.CreateDiscount(DiscountTypes.Fixed, 1, 1M, DateTime.Now, "", 0, status.ShowID);
                ShowDiscounts.CreateDiscount(DiscountTypes.TransactionCharge, 1, 0.5M, DateTime.Now, "", 0, status.ShowID);
            }
            return 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 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;
        }
        public StatusCls AdminPayForShow(ShowEntry showEntry)
        {
            StatusCls status = new StatusCls();
            var currentUser = new User(showEntry.UserId);
            var thisShow = new Shows(showEntry.ShowId);
            var us = new UserShows(showEntry.UserId, showEntry.ShowId);
            us.Status = us.Status = (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID;
            us.Save();
            status.Data = us.ID.ToString().PadLeft(6, '0');
            var transactions = Transaction.getTransactionForShowRef(us.ID);
            var transID = Transaction.Add(status.Data, TransactionTypes.ShowEntryPayment, showEntry.Cheque, showEntry.PaymentType + " Payment", showEntry.ShowId, showEntry.UserId, DateTime.Now, showEntry.Cheque);
            Transaction.SetEnteredBy(transID, Transaction.ENTERED_BY.SHOW_ADMIN_ENTRY);

            if (thisShow.Status == 0)
            {
                return status;
            }

            if (currentUser.EmailAddress.Length > 0)
            {
                // if entered show, send email saying entered show
                String htmlContents = readTemplate("AdminEnteredShowMessage", "html", thisShow, status.Data);
                String plainContents = readTemplate("AdminEnteredShowMessage", "txt", thisShow, status.Data);

                String Classes_entered_html = "<table>";
                String Classes_entered_plain = "";

                List<ShowClasses> classList = ShowClasses.GetAllClassesForShow(showEntry.ShowId);
                List<Dogs> dogList = Dogs.GetAllDogsForHandler(showEntry.UserId, thisShow.ShowDate);
                foreach (Dogs d in dogList)
                {

                    DogClasses dogClasses = new DogClasses(d.ID, showEntry.ShowId);
                    dogClasses.getDogsClasses(showEntry.ShowId);
                    string dogClassesPlain = String.Format("{1}{0}{1}--------------------------------{1}", d.PetName, Environment.NewLine);
                    string dogClassesHtml = String.Format("<tr style='font-weight:bold;'><td colspan='3'><b>{0}</b></td></tr>", d.PetName);
                    bool dogEntered = false;
                    foreach (ShowClasses cls in classList)
                    {
                        int clsIndex = dogClasses.Classlist.IndexOf(cls.ID);
                        if (clsIndex > -1)
                        {
                            dogEntered = true;
                            dogClassesHtml += "<tr>";
                            dogClassesHtml += String.Format("<td style='width:25px'></td><td>{0}</td><td>{1} {2} {3} {4}</td>", cls.ClassNo, cls.longHeight, cls.LongClassName, cls.longCatagory, cls.getGrades);
                            dogClassesHtml += "</tr>";
                            dogClassesPlain += String.Format("{0} - {1} {2} {3} {4} {5}", cls.ClassNo, cls.longHeight, cls.LongClassName, cls.longCatagory, cls.getGrades, Environment.NewLine);
                        }
                    }

                    if (dogEntered)
                    {
                        Classes_entered_html += dogClassesHtml;
                        Classes_entered_plain += dogClassesPlain;
                    }
                }
                Classes_entered_html += "</table>";
                Classes_entered_plain += Environment.NewLine;

                htmlContents = htmlContents.Replace("[CLASSES_ENTERED]", Classes_entered_html);
                plainContents = plainContents.Replace("[CLASSES_ENTERED]", Classes_entered_plain);

                String underPayment_html = "";
                String underPayment_plain = "";
                if (showEntry.Cheque < showEntry.Total)
                {
                    if (Math.Abs(showEntry.Total - showEntry.Cheque) >= 5)
                    {
                        underPayment_html = String.Format("<h2>Please note that you entry was underpaid by £{0:.00}. Please send the balance to the Show Processor ASAP.</h2>", Math.Abs(showEntry.Total - showEntry.Cheque));
                        underPayment_plain = String.Format("Please note that you entry was underpaid by £{0:.00}. Please send the balance to the Show Processor ASAP.", Math.Abs(showEntry.Total - showEntry.Cheque));
                    }
                    else
                    {
                        underPayment_html = String.Format("<h2>Please note that you entry was underpaid by £{0:.00}. Please pay the outstanding balance at the show.</h2>", Math.Abs(showEntry.Total - showEntry.Cheque));
                        underPayment_plain = String.Format("Please note that you entry was underpaid by £{0:.00}. Please pay the outstanding balance at the show.", Math.Abs(showEntry.Total - showEntry.Cheque));
                    }
                }

                htmlContents = htmlContents.Replace("[PAYMENT_NOTE]", underPayment_html);
                plainContents = plainContents.Replace("[PAYMENT_NOTE]", underPayment_plain);

                String camping_html = "";
                String camping_plain = "";
                UserCamping userCamping = new UserCamping(us.ID);
                if (userCamping.ID > -1)
                {
                    String[] daysSplit = userCamping.PitchDetails[0].CampingDays.Split(',');
                    String Days = "";
                    foreach (String day in daysSplit)
                    {
                        DateTime dt = Convert.ToDateTime(day);
                        if (Days.Length > 1) Days += ", ";
                        Days += dt.ToString("ddd");
                    }
                    camping_html = String.Format("<h3>Camping Confirmation</h3><p>Camping Group Name: <b>{0}</b></p><p>Nights Camping: <b>{1}</b></p><p>Number Of Pitches: <b>{2}</b></p>", userCamping.PitchDetails[0].PartyName, Days, userCamping.PitchDetails.Count());
                    camping_plain = String.Format("Camping Confirmation{3}--------------------{3}Camping Group Name:{0}{3}Nights Camping:{1}{3}Number Of Pitches: {2}{3}", userCamping.PitchDetails[0].PartyName, Days, userCamping.PitchDetails.Count(), Environment.NewLine);

                }
                htmlContents = htmlContents.Replace("[CAMPING]", camping_html);
                plainContents = plainContents.Replace("[CAMPING]", camping_plain);

                if (currentUser.firstTime)
                {
                    String prelogon = Guid.NewGuid().ToString();
                    prelogon = "?verify=" + prelogon.Substring(0, prelogon.Length - 4) + showEntry.UserId.ToString().PadLeft(4, '0');

                    htmlContents = htmlContents.Replace("[PRELOGON]", prelogon);
                    plainContents = plainContents.Replace("[PRELOGON]", prelogon);
                }
                else
                {
                    String prelogon = Guid.NewGuid().ToString();
                    prelogon = "?quick=" + prelogon.Substring(0, prelogon.Length - 4) + showEntry.UserId.ToString().PadLeft(4, '0');

                    htmlContents = htmlContents.Replace("[PRELOGON]", prelogon);
                    plainContents = plainContents.Replace("[PRELOGON]", prelogon);
                }
                MailMessage mm = new MailMessage();

                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlContents, null, MediaTypeNames.Text.Html);
                LinkedResource logoImage = new LinkedResource(HttpContext.Current.Server.MapPath("/Content/Assets/logo.gif"), MediaTypeNames.Image.Gif);
                logoImage.ContentId = "LogoImage";
                //htmlView.LinkedResources.Add(logoImage);

                AlternateView plainView = AlternateView.CreateAlternateViewFromString(plainContents, null, MediaTypeNames.Text.Plain);
                mm.Body = plainContents;
                mm.AlternateViews.Add(htmlView);

                try
                {
                    SmtpClient client = new SmtpClient();
                    mm.From = new MailAddress("*****@*****.**", "First Place Processing");
                    mm.To.Add(new MailAddress(currentUser.EmailAddress, currentUser.Name));
                    mm.Subject = String.Format("Show Confirmation - {0} ({1:dd MMM yyyy})", thisShow.ShowName, thisShow.ShowDate);
                    client.Send(mm);
                }
                catch (Exception e)
                {
                    AppException.LogEvent("Error Sending Email from AdminEntered Show:" + e.Message + "-" + e.StackTrace);
                }
            }

            return status;
        }
        public StatusCls AdminEnteredShow(UserShowEntry showEntry)
        {
            StatusCls status = new StatusCls();
            status.Status = 0;
            status.UserID = showEntry.UserId;

            UserShows us = EntryDetails.SaveEntryv2(showEntry);
            us.Optout = showEntry.OptOut;
            us.HandlerType = showEntry.HandlerType;
            us.Save();
            status.Data = us.ID.ToString().PadLeft(6, '0');
            status.ShowStatus = us.Status;
            var transactions = Transaction.getTransactionForShowRef(us.ID);
            if (transactions.Any(x => x.EnteredBy == (int)Transaction.ENTERED_BY.ONLINE_ENTRY))
            {
                var balance = transactions.Sum(x => x.Amount);
                if (balance + showEntry.Total != 0)
                {
                    int transID = Transaction.Add(status.Data, TransactionTypes.ShowEntry, -showEntry.Total, "Admin Entry(2)", showEntry.ShowId, showEntry.UserId, DateTime.Now, -showEntry.Total);
                }
            }
            else
            {
                var balance = transactions.Sum(x => x.Amount);
                if (balance + showEntry.Total != 0)
                {
                    int transID = Transaction.Add(status.Data, TransactionTypes.ShowEntry, -showEntry.Total, "Admin Entry(1)", showEntry.ShowId, showEntry.UserId, DateTime.Now, showEntry.Total);
                    Transaction.SetEnteredBy(transID, Transaction.ENTERED_BY.SHOW_ADMIN_ENTRY);
                }

                if (showEntry.DiscountAmount > 0)
                {
                    var showTransactions = Transaction.GetTransactionForShowUser(us.ID);
                    var discounts = showTransactions.Where(x => x.TransactionType == TransactionTypes.Discount).Sum(t => t.Amount);
                    showEntry.DiscountAmount -= discounts;
                    if (showEntry.DiscountAmount < 0) showEntry.DiscountAmount = 0;

                    Transaction.Add(us.ID.ToString("000000"), TransactionTypes.Discount, showEntry.DiscountAmount, "Discount Applied", us.ShowID, us.Userid, DateTime.Now);
                }

            }
            if (showEntry.AddTransactionCharge)
            {
                var fixedFee = ShowDiscounts.getDiscountsByType(showEntry.ShowId, -1, (int)DiscountTypes.TransactionCharge).FirstOrDefault();
                Transaction.Add(us.ID.ToString("000000"), TransactionTypes.TransactionCharge, -fixedFee.Amount, "Transaction Fee", us.ShowID, us.Userid, DateTime.Now);
            }
            return status;
        }
        // From Website
        public StatusCls GetSummaryForm(int ShowId, int UserId)
        {
            StatusCls status = new StatusCls();
            PaymentSummary paymentSummary = new PaymentSummary();
            Shows thisShow = new Shows(ShowId);
            User currentUser = new User(UserId);
            var us = new UserShows(UserId, ShowId);

            var singleEntryId = getSingleEntry(ShowId);

            decimal totals = 0;
            var transactions = GetTransactionDetails(us.ID, ref totals);

            String showDetailsBox = "";
            showDetailsBox += "<div class='showDetails summary themeText'>";
            showDetailsBox += "<div class='title' style='width:700px'>" + thisShow.ShowName + "</div>";
            showDetailsBox += "<div class='showdate'>" + thisShow.ShowDate.ToString("dd MMM yyyy") + "</div>";
            showDetailsBox += "</div >";

            String totalsBox = "";
            totalsBox += status.ShowSummary;
            totalsBox += "<div class='ctrlButtons'></div>";
            totalsBox += "<div class='totalSummary '>";
            if (us.Status == (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID)
            {
                if (totals < 0)
                {
                    var refundRequests = transactions.Where(x => x.TransactionType == TransactionTypes.RefundRequest );
                    var refundPaid = transactions.Where(x => x.TransactionType == TransactionTypes.RefundPaid || x.TransactionType == TransactionTypes.RefundPaid);
                    if (refundRequests.Any() && (refundRequests.Count() != refundPaid.Count()))
                    {
                        totalsBox += string.Format("<div class='notpaid'><h3>Pending Refund: £{0:0.00}</h3></div>", Math.Abs(totals));
                    }
                    else
                    {
                        totalsBox += string.Format("<div class='notpaid'><h3>Awaiting payment: £{0:0.00}</h3></div>", Math.Abs(totals));
                        totalsBox += createPaymentForm(currentUser, thisShow, us.ID, Math.Abs(totals));
                    }
                }
                else if (totals > 0)
                {
                    if (transactions.Any(x => x.TransactionType == TransactionTypes.ShowEntryPayment))
                    {
                        totalsBox += "<div class='notpaid'><h3>Show Paid</h3></div>";
                    }
                    else
                    {
                        totalsBox += string.Format("<div class='notpaid'><h3>Awaiting payment: £{0:0.00}</h3></div>", Math.Abs(totals));
                        totalsBox += createPaymentForm(currentUser, thisShow, us.ID, totals);
                    }
                }
                else
                {
                    totalsBox += "<div class='paid'><h3>Show Paid</h3></div>";
                }
            }
            else if (us.Status == (int)UserShows.UserStatus.STATUS_ENTERED_NOT_PAID || us.Status == (int)UserShows.UserStatus.STATUS_SAVED)
            {
                if (transactions.Any())
                {
                    totals = GetOutstandingBalance(us) * -1;

                    if (totals < 0)
                    {
                        totalsBox += string.Format("<div class='notpaid'><h3>Awaiting payment: £{0:0.00}</h3></div>", Math.Abs(totals));
                        totalsBox += createPaymentForm(currentUser, thisShow, us.ID, totals * -1);
                    }
                    else if (totals > 0)
                    {
                        totalsBox += "<div class='notpaid'>Refund Due</div>";
                    }
                }
                else
                {

                }
            }
            String userRefNo = us.ID.ToString().PadLeft(6, '0');

            totalsBox += "</div >";

            String docbox = "<div class='summaryDocs'>";
            docbox += "</div>";
            docbox += "<div class='buttons'>";
            if (thisShow.Status == (int)Shows.SHOW_STATUS.SHOWDOCS_AVAILABLE)
            {
                docbox += "<input type='button' class='button-document bigButtons' data-action='rp' value='Your Running Plan' />";
                docbox += "<input type='button' class='button-document bigButtons' data-action='rpb' value='Blank Running Plan' />";

                String baseURL = "/Schedules/" + thisShow.ShowDate.ToString("yyyy") + "/";
                List<ShowDocuments> showDocs = Shows.getShowDocuments(ShowId);
                foreach (ShowDocuments doc in showDocs.Where( x=> x.Name == "other" ) )
                {
                    docbox += String.Format("<input type='button' class='button-document bigButtons' style='text-transform:Capitalize;' data-action='other' data-url='{0}{1}' value='Show Information' />", baseURL, doc.Url, doc.Name);
                }

            }
            if (thisShow.Status >= (int)Shows.SHOW_STATUS.CLOSED)
            {
                //docbox += "<input type='button' class='btns' action='os' value='View Entry' showstatus='" + thisShow.Status.ToString() + "' />";
                if (us.Status == (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID)
                {
                    docbox += "<div class='entrySummary'>" + getEntrySummary(us) + "</div>";
                }
            }
            else
            {
                docbox += "<div class='entrySummary'>" + getEntrySummary(us) + "</div>";
                if (thisShow.Status != (int)Shows.SHOW_STATUS.SHOWDOCS_AVAILABLE)
                {
                    docbox += "<input type='button' class='btns' action='os' value='Edit Entry'  />";
                    docbox += "<input type='button' class='btns' action='ce' value='Cancel Entry'  />";
                }
            }
            docbox += "<input type='button' class='btns' action='close' value='Close' />";
            docbox += "</div>";
            status.Status = 0;
            status.UserID = currentUser.ID;
            status.Camping = new Camping(ShowId);
            status.CampingSummary = UserCamping.GetCampingSummary(ShowId, currentUser.ID);
            if (!status.CampingSummary.Any())
            {
                for (DateTime dt = status.Camping.Startdate; dt <= status.Camping.Enddate; dt = dt.AddDays(1))
                {
                    status.CampingSummary.Add(new Core.Dto.CampingSummary
                    {
                        CampingDay = dt,
                        Count = 0
                    });
                }
            }
            else
            {
                status.CampingFull = status.CampingSummary.Where(x => x.Count >= status.Camping.Limit).Count() == status.CampingSummary.Count();
            }
            status.PaymentSummary = CreatePaymentSummary(us, false, status.CampingFull);
            if (status.Camping.ID > -1 && !status.CampingFull)
            {
                status.UserCamping = new UserCamping(us.ID);
            }

            status.Data = "<input id='ShowID' type='hidden' value='" + ShowId.ToString() + "' />" +
                          "<div class='summary' showid='" + ShowId.ToString() + "'>" + showDetailsBox + totalsBox + docbox + "</div>";

            status.Extra = totalsBox;
            if (us.Status == (int)UserShows.UserStatus.STATUS_ENTERED_NOT_PAID)
            {
                status.Extra = createPaymentForm(currentUser, thisShow, us.ID, totals);
            }
            status.ShowStatus = thisShow.Status;
            status.PaymentSummary = CreatePaymentSummary(us);
            status.Helping = Business.Helpers.HelperForShow(us.ShowID, us.Userid);
            return status;
        }