public static UserShows SaveEntry(ShowEntry showEntry)
        {
            DogClasses dc = new DogClasses();
            String[] dogs = new String[] { };
            if (showEntry.EnterData != null)
            {
                dogs = showEntry.EnterData.Split(',');
            }
            else
            {
                AppException.LogEvent(string.Format("SaveEntry: data length = 0, {0}{1}", showEntry.ShowId, showEntry.UserId));
            }
            var altHandlersList = new string[] { };
            if (showEntry.AltHandlersList != null)
            {
                altHandlersList = showEntry.AltHandlersList.Split(',');
            }

            //
            //  Multidog format is packed as
            //  <dogid>@<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>][,<dogid>#<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>]](captain$$teamname)
            //
            MultiDog.DeleteUserFromShow(showEntry.UserId, showEntry.ShowId);

            if (!string.IsNullOrEmpty(showEntry.PairsTeams))
            {
                var spt = Regex.Split(showEntry.PairsTeams, "[|]");
                var captain = "";
                var teamName = "";
                if (spt.Length > 1)
                {
                    var s = Regex.Split(spt[1], "[$]");
                    captain = s[0];
                    teamName = s[1];
                    if (captain.Length > 0 && teamName.Length > 0)
                    {
                        MultiDog.AddTeamPairsDetails(showEntry.ShowId, showEntry.UserId, captain, teamName,1,-1);
                    }
                }
                var pairTeams = spt[0].Split(',');
                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(1, showEntry.UserId, DogID, ClsID, showEntry.ShowId, handlerName, dogName, handlerID, dogID,1);
                            }
                            else
                            {
                                MultiDog.Add(showEntry.UserId, DogID, ClsID, showEntry.ShowId, 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(1, showEntry.UserId, DogID, ClsID, showEntry.ShowId, handlerName, dogName, handlerID, dogID,1);
                            }
                        }
                    }
                }
            }

            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, showEntry.ShowId, classes, altHandlers, -1);
            }

            UserShows us = new UserShows(showEntry.UserId, showEntry.ShowId);
            us.Status = us.Status = (int)UserShows.UserStatus.STATUS_SAVED;

            //
            // add check to see if this person is on the judging list.
            if (showEntry.HandlerType != (int)UserShows.HandlerTypes.MEMBER
                && Judge.isJudgeAtShow(showEntry.UserId, showEntry.ShowId))
            {
                us.HandlerType = (int)UserShows.HandlerTypes.JUDGE;
            }
            else
            {
                us.HandlerType = showEntry.HandlerType;
            }
            us.Optout = showEntry.OptOut;
            us.DogsMeasured = showEntry.DogsMeasured;
            us.Save();

            Camping camping = new Camping(showEntry.ShowId);
            if (camping.ID > -1)
            {
                if (!string.IsNullOrEmpty(showEntry.CampingDays))
                {
                    UserCamping.DeleteForUser(us.ID);
                    for (var i = 0; i < showEntry.Plots; i++)
                    {
                        UserCamping.Add(us.ID, showEntry.CampingParty, showEntry.CampComments, showEntry.CampingDays, showEntry.PitchSize);
                    }
                }
            }

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

            return us;
        }
        private ShowEntry GetCurrentEntry(int ShowId, int UserId, int handlerType)
        {
            var currentEntry = new ShowEntry();
            var us = new UserShows(UserId, ShowId);
            currentEntry.HandlerType = us.HandlerType;
            currentEntry.OptOut = us.Optout;
            currentEntry.EnterData = "";

            Shows thisShow = new Shows(ShowId);
            Dogs dog = new Dogs();
            var DogDetails = Dogs.GetAllDogsForHandler(UserId, thisShow.ShowDate);
            var UserDetails = new User(UserId);

            var classList = ShowClasses.GetAllClassesForShow(ShowId);
            List<validClassesForDog> validDogClasses = new List<validClassesForDog>();
            foreach (Dogs d in DogDetails)
            {
                if (currentEntry.EnterData.Length > 0) currentEntry.EnterData += ",";

                validClassesForDog vc4d = new validClassesForDog(d.ID);
                validDogClasses.Add(vc4d);
                DogClasses dc = new DogClasses(d.ID, ShowId);
                dc.getDogsClasses(ShowId);
                currentEntry.EnterData += String.Format("{0}:", d.ID);
                foreach (ShowClasses cls in classList)
                {
                    if (dc.Classlist.IndexOf(cls.ID) > -1)
                    {
                        currentEntry.EnterData += cls.ID + ".";
                    }
                }
            }
            var userCamping = UserCamping.GetUserShow(us.ID);
            if (userCamping.ID > -1)
            {
                currentEntry.CampingDays = userCamping.PitchDetails[0].CampingDays;
                currentEntry.CampingParty = userCamping.PitchDetails[0].PartyName;
                currentEntry.CampComments = userCamping.PitchDetails[0].Comments;
                currentEntry.Plots = userCamping.PitchDetails.Count();
            }

            return currentEntry;
        }
        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;
        }
        private bool CheckForDifferentEntries(ShowEntry previousEntry, ShowEntry showEntry)
        {
            var prevDogs = new List<DogClass>();
            var currentDogs = new List<DogClass>();
            foreach (string dog in previousEntry.EnterData.Split(','))
            {
                prevDogs.Add(new DogClass(dog));
            }

            foreach (string dog in showEntry.EnterData.Split(','))
            {
                currentDogs.Add(new DogClass(dog));
            }

            if (prevDogs.Count() == currentDogs.Count())
            {
                foreach (DogClass dc in prevDogs)
                {
                    var dog = currentDogs.Where(x => x.DogId == dc.DogId);
                    if (dog != null)
                    {
                        if (dog.FirstOrDefault().ClassIds.Count() != dc.ClassIds.Count())
                        {
                            return false;
                        }
                    }
                    else
                        return false;
                }
            }
            else
            {
                return false;
            }

            return true;
        }