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

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

            }
            catch (Exception e)
            {
                AppException.LogError($"Error:ChangeClasses:{e.Message}, {e.StackTrace}");
            }
        }
        public 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;
        }
        public static UserShows SaveEntryv2(UserShowEntry showEntry)
        {
            DogClasses dc = new DogClasses();
            var altHandlersList = new string[] { };
            UserShows us = new UserShows(showEntry.UserId, showEntry.ShowId);
            try
            {
                MultiDog.DeleteUserFromShow(showEntry.UserId, showEntry.ShowId);
                try
                {
                    if (showEntry.MultiDogEntries != null && showEntry.MultiDogEntries.Any())
                    {
                        var idx = 1;
                        var teamPairsId = 0;
                        foreach (var md in showEntry.MultiDogEntries)
                        {
                            teamPairsId = MultiDog.AddTeamPairsDetails(showEntry.ShowId, showEntry.UserId, md.TeamDetails.Captain, md.TeamDetails.TeamName, idx, md.ClassId);
                            foreach (var member in md.Members)
                            {
                                MultiDog.Add(teamPairsId, showEntry.UserId, member.DogId, md.ClassId, showEntry.ShowId, member.HandlerName ?? "", member.DogName ?? "", member.HandlerId, member.DogId, idx);
                            }
                            idx++;
                        }
                    }
                }
                catch (Exception e)
                {
                    AppException.Log(string.Format("SaveEntryv2 Error MultiDogs  (ShowId={0}, UserId={1} [{2}][{3}]", showEntry.ShowId, showEntry.UserId, e.Message, e.StackTrace), "");
                }

                foreach (DogsModel dog in showEntry.Dogs)
                {
                    dc.Save(showEntry.ShowId, dog);

                    if (dog.ClassNo != null)
                    {
                        var ykc = dog.ClassNo.Where(y => y.Juniors != null);
                        if (ykc.Any())
                        {
                            var y = ykc.First();
                            if (y.Juniors.Id == 0)
                            {
                                Juniors.AddJunior(dog.Id, y.Id, y.Juniors.DoB, y.Juniors.YKCNumber);
                            }
                            else
                            {
                                var jnr = new Juniors(y.Juniors.Id);
                                jnr.DogId = dog.Id;
                                jnr.ClassId = y.Id;
                                jnr.YKCNumber = y.Juniors.YKCNumber;
                                jnr.DoB = y.Juniors.DoB;
                                jnr.Save();
                            }
                        }
                        var g7dogs = dog.ClassNo.Where(x => x.ChampWins != null && x.ChampWins.Any());
                        foreach (var d in g7dogs)
                        {
                            foreach (var win in d.ChampWins)
                            {
                                if (!string.IsNullOrEmpty(win.ShowName) && !string.IsNullOrEmpty(win.ShowClass))
                                {
                                    DateTime parsedDate = DateTime.MinValue;
                                    if (!DateTime.TryParseExact(win.ShowDate, "dd-MM-yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate))
                                    {
                                        DateTime.TryParseExact(win.ShowDate, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate);
                                    }

                                    Fpp.Business.DogHistory.AddChampWins(new Core.Views.UpgradeDogView
                                    {
                                        Id = win.Id,
                                        ShowName = win.ShowName,
                                        ClassWon = win.ShowClass,
                                        WinDate = parsedDate,
                                        UserId = showEntry.UserId,
                                        DogId = dog.Id,
                                        NewGrade = 7,
                                        Comments = "Win towards grade 7",
                                        UpgradeType = win.UpgradeType,
                                        DateOfWin = win.ShowDate
                                    });

                                }
                            }
                        }
                    }
                }

                if (us.Status != (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID)
                {
                    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)
                {

                    var oldcamp = new UserCamping(us.ID);
                    UserCamping.DeleteForUser(us.ID);
                    if (showEntry.UserCamping != null)
                    {
                        for (var i = 0; i < showEntry.UserCamping.Plots; i++)
                        {
                            UserCamping.Add(us.ID, showEntry.UserCamping);
                        }
                        var uc = new UserCamping(us.ID);

                        if (oldcamp.ID > -1 && oldcamp.PitchDetails.Any() )
                        {
                            UserCamping.SetCode(uc.PitchDetails[0].ID, oldcamp.PitchDetails[0].CampingCode);
                            UserCamping.SetComments(uc.PitchDetails[0].ID, oldcamp.PitchDetails[0].Comments);
                            UserCamping.SetPitchNo(uc.PitchDetails[0].ID, oldcamp.PitchDetails[0].PitchNo);
                            if (uc.PitchDetails.Count > 1 && oldcamp.PitchDetails.Count > 1)
                            {
                                UserCamping.SetCode(uc.PitchDetails[1].ID, oldcamp.PitchDetails[1].CampingCode);
                                UserCamping.SetComments(uc.PitchDetails[1].ID, oldcamp.PitchDetails[1].Comments);
                                UserCamping.SetPitchNo(uc.PitchDetails[1].ID, oldcamp.PitchDetails[1].PitchNo);
                            }

                        }

                    }
                }

                if (showEntry.UserCamping != null && showEntry.UserCamping.WaitingList == 1)
                {
                    WaitingList.Add(showEntry.ShowId, showEntry.UserId);
                }

            }
            catch (Exception e)
            {
                AppException.Log( string.Format("SaveEntryv2 Error (ShowId={0}, UserId={1} [{2}][{3}]", showEntry.ShowId, showEntry.UserId, e.Message, e.StackTrace), "");
            }
            return us;
        }