Пример #1
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            var phaseReportChars = db.PhaseReports.Where(x => x.MemberCharacter.Member_Id == id).ToList();

            db.BulkDelete(phaseReportChars);
            db = new SwgohDb();
            var phaseReportShips = db.PhaseReports.Where(x => x.MemberShip.Member_Id == id).ToList();

            db.BulkDelete(phaseReportShips);
            db = new SwgohDb();

            Member member = db.Members.Find(id);
            Guild  guild  = db.Guilds.Find(member.Guild_Id);

            guild.CharacterPower  = guild.CharacterPower - member.CharacterPower;
            guild.ShipPower       = guild.ShipPower - member.ShipPower;
            db.Entry(guild).State = EntityState.Modified;
            db.Members.Remove(member);
            db.Entry(guild).State = EntityState.Modified;
            db.SaveChanges();

            var tbps = db.TerritoryBattlePhases.Where(x => x.TerritoryBattle.Guild_Id == guild.Id);

            foreach (var tbp in tbps)
            {
                tbp.RefreshReport = true;
            }

            db.BulkUpdate(tbps);

            return(RedirectToAction("Details", "Guilds", new { id = member.Guild_Id }));
        }
Пример #2
0
        public ActionResult About()
        {
            var dbConn = new SwgohDb();

            ViewBag.Connection = dbConn.Database.Connection.ConnectionString;
            ViewBag.Message    = "Your application description page.";

            return(View());
        }
Пример #3
0
        public ActionResult Register()
        {
            SwgohDb db = new SwgohDb();

            RegisterViewModel vm = new RegisterViewModel();

            vm.Guilds = db.Guilds.OrderBy(x => x.Name).ToList();
            return(View(vm));
        }
        public ActionResult ManageResults(TerritoryBattleResultsModel territoryBattleResultsModel)
        {
            if (ModelState.IsValid)
            {
                List <PhaseTerritory> phaseTerritories = db.PhaseTerritories
                                                         .Where(x => x.TerritoryBattlePhase.TerritoryBattle_Id == territoryBattleResultsModel.Id).ToList();

                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 1).TotalPointsEarned =
                    territoryBattleResultsModel.Phase1Points;

                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 2 && x.PhaseLocation == "Middle").TotalPointsEarned =
                    territoryBattleResultsModel.Phase2TopCharPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 2 && x.PhaseLocation == "Bottom").TotalPointsEarned =
                    territoryBattleResultsModel.Phase2BottomCharPoints;

                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 3 && x.PhaseLocation == "Top").TotalPointsEarned =
                    territoryBattleResultsModel.Phase3FleetPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 3 && x.PhaseLocation == "Middle").TotalPointsEarned =
                    territoryBattleResultsModel.Phase3TopCharPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 3 && x.PhaseLocation == "Bottom").TotalPointsEarned =
                    territoryBattleResultsModel.Phase3BottomCharPoints;

                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 4 && x.PhaseLocation == "Top").TotalPointsEarned =
                    territoryBattleResultsModel.Phase4FleetPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 4 && x.PhaseLocation == "Middle").TotalPointsEarned =
                    territoryBattleResultsModel.Phase4TopCharPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 4 && x.PhaseLocation == "Bottom").TotalPointsEarned =
                    territoryBattleResultsModel.Phase4BottomCharPoints;

                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 5 && x.PhaseLocation == "Top").TotalPointsEarned =
                    territoryBattleResultsModel.Phase5FleetPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 5 && x.PhaseLocation == "Middle").TotalPointsEarned =
                    territoryBattleResultsModel.Phase5TopCharPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 5 && x.PhaseLocation == "Bottom").TotalPointsEarned =
                    territoryBattleResultsModel.Phase5BottomCharPoints;

                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 6 && x.PhaseLocation == "Top").TotalPointsEarned =
                    territoryBattleResultsModel.Phase6FleetPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 6 && x.PhaseLocation == "Middle").TotalPointsEarned =
                    territoryBattleResultsModel.Phase6TopCharPoints;
                phaseTerritories.FirstOrDefault(x => x.TerritoryBattlePhase.Phase == 6 && x.PhaseLocation == "Bottom").TotalPointsEarned =
                    territoryBattleResultsModel.Phase6BottomCharPoints;

                db = new SwgohDb();
                db.BulkUpdate(phaseTerritories);
                //db.Entry(territoryBattle).State = EntityState.Modified;
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(territoryBattleResultsModel));
        }
        public ActionResult NewPlatoonAssignments(Guid id, Guid?memberId, Guid?guildId = null)
        {
            TerritoryBattlePhase tbp = db.TerritoryBattlePhases.Find(id);

            ViewBag.PhaseNumber = tbp.Phase;

            var members = db.Members.Where(x => x.Guild_Id == tbp.TerritoryBattle.Guild_Id).Select(s => new
            {
                Text  = s.DisplayName,
                Value = s.Id
            }).OrderBy(x => x.Text).AsEnumerable();

            SelectList selectList = new SelectList(members.ToList(), "Value", "Text");

            TerritoryPhaseReportModel model = new TerritoryPhaseReportModel()
            {
                Members  = selectList,
                MemberId = memberId,
                Id       = id,
            };

            ViewBag.GuildId = guildId;

            if (tbp.RefreshReport)
            {
                foreach (DictionaryEntry key in HttpContext.Cache)
                {
                    HttpContext.Cache.Remove(key.Key.ToString());
                }

                db.BulkDelete(db.PhaseReports.Where(x => x.TerritoryBattlePhase_Id == id).ToList());

                db = new SwgohDb();
                var tbpUpdate = db.TerritoryBattlePhases.Find(id);
                tbpUpdate.RefreshReport = false;

                db.Entry(tbpUpdate).State = EntityState.Modified;
                db.SaveChanges();
                db = new SwgohDb();
            }

            return(View(model));
        }
        public ActionResult GetRoster(Guid id)
        {
            var guild = db.Guilds.Find(id);

            if (guild == null)
            {
                return(HttpNotFound());
            }

            if (DateTime.Now < guild.LastScrape.AddHours(6) && !guild.LastScrape.Equals(DateTime.Parse("1900-01-01 00:00:00.000")) && !User.IsInRole("Administrators"))
            {
                ViewBag.Error = "Please wait until " + guild.LastScrape.AddHours(1).ToShortTimeString() + " to run again.";
                return(RedirectToAction("Details", new { id }));
            }

            if (!User.IsInRole("Administrators"))
            {
                guild.LastScrape      = DateTime.Now;
                db.Entry(guild).State = EntityState.Modified;
                db.SaveChanges();
                db = new SwgohDb();
            }

            var tbps = db.TerritoryBattlePhases.Where(x => x.TerritoryBattle.Guild_Id == id);

            foreach (var tbp in tbps)
            {
                tbp.RefreshReport = true;
            }
            db = new SwgohDb();
            db.BulkUpdate(tbps);

            var db1      = new SwgohDb();
            var toDelete = db1.PhaseReports.Where(x => x.GuildId == id);

            db.BulkDelete(toDelete);
            UpdateRoster(id, guild);

            return(RedirectToAction("Index", "Members", new { id }));
        }
Пример #7
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (UserManager.Users.Any(x => x.Email == model.Email))
                {
                    SwgohDb db = new SwgohDb();

                    model.Guilds = db.Guilds.ToList();

                    ViewBag.Error = "User already exists for that email.";
                    return(View(model));
                }

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Guild_Id = model.Guild_Id
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        private void UpdateRoster(Guid id, Guild guild)
        {
            db = new SwgohDb();
            IEnumerable <Member>    members    = db.Members.Include(x => x.MemberCharacters).Include(x => x.MemberShips).Where(x => x.Guild_Id == id).ToList();
            IEnumerable <Character> characters = db.Characters.ToList();
            IEnumerable <Ship>      ships      = db.Ships.ToList();

            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(guild.UrlExt + "gp/");

            string guildMemberTable = doc.DocumentNode.SelectNodes("/html/body/div[3]/div[1]")[0].InnerHtml;

            guildMemberTable = guildMemberTable.Substring(guildMemberTable.IndexOf("<tbody>") + 7);
            Regex regexChar = new Regex(@"\n");
            Regex regex     = new Regex(@"<tr>");

            string[] substrings = regex.Split(guildMemberTable);
            //substrings = substrings.Skip(1).ToArray();
            List <string> listMembers = substrings.ToList();

            //listMembers.RemoveRange(0,2);

            listMembers.Remove("\n");

            List <Member>          newMembers          = new List <Member>();
            List <Member>          updateMembers       = new List <Member>();
            List <MemberCharacter> memberCharactersAdd = new List <MemberCharacter>();
            List <MemberShip>      memberShipsAdd      = new List <MemberShip>();

            List <Member> memberDelete = new List <Member>();

            List <string> memberExt = new List <string>();

            foreach (var member in listMembers)
            {
                string[] memberSplit = member.Split('"');
                memberExt.Add("https://swgoh.gg" + memberSplit[3] + "characters/");
            }

            foreach (var member in members)
            {
                if (!memberExt.Any(x => x.Contains(member.UrlExt)))
                {
                    memberDelete.Add(db.Members.FirstOrDefault(x => x.UrlExt == member.UrlExt));
                    db.SaveChanges();
                    db = new SwgohDb();
                }
            }
            foreach (var member in memberDelete)
            {
                var phaseReportChars = db.PhaseReports.Where(x => x.MemberCharacter.Member_Id == member.Id).ToList();
                db.BulkDelete(phaseReportChars);
                db = new SwgohDb();
                var phaseReportShips = db.PhaseReports.Where(x => x.MemberShip.Member_Id == member.Id).ToList();
                db.BulkDelete(phaseReportShips);
                db = new SwgohDb();
            }
            db.BulkDelete(memberDelete);
            db = new SwgohDb();

            foreach (var member in listMembers)
            {
                Member   guildMember = new Member();
                string[] memberSplit = member.Split('"');
                string   charHref    = "https://swgoh.gg" + memberSplit[3] + "characters/";
                string   shipHref    = "https://swgoh.gg" + memberSplit[3] + "ships/";
                string   name        = Regex.Replace(memberSplit[4], "(?s).*?(?<=<strong>)", String.Empty); // memberSplit[2].Substring(10).Replace("</strong>\n</a>\n</td>\n<td class=", "");
                name = name.Remove(name.IndexOf("</strong>", StringComparison.Ordinal));

                string toConvertChar = memberSplit[8].Replace(">", "").Replace(" ", "").Replace("</td\n<tdclass=", "");
                string toConvertShip = memberSplit[10].Replace(" ", "").Replace(">", "").Replace("</td\n</tr\n", "")
                                       .Replace("</tbody\n</table\n</div\n</li\n", "").Replace("</ul\n</div\n", "");

                if (members.Any(x => x.UrlExt.Equals(charHref)))
                {
                    guildMember                = members.FirstOrDefault(x => x.UrlExt.Equals(charHref));
                    guildMember.Name           = name;
                    guildMember.DisplayName    = HttpUtility.HtmlDecode(name);
                    guildMember.CharacterPower = Convert.ToInt32(toConvertChar);
                    guildMember.ShipPower      = Convert.ToInt32(toConvertShip);
                    updateMembers.Add(guildMember);
                }
                else
                {
                    guildMember.Id             = Guid.NewGuid();
                    guildMember.Name           = name;
                    guildMember.DisplayName    = HttpUtility.HtmlDecode(name);
                    guildMember.UrlExt         = charHref;
                    guildMember.Guild_Id       = guild.Id;
                    guildMember.CharacterPower = Convert.ToInt32(toConvertChar);
                    guildMember.ShipPower      = Convert.ToInt32(toConvertShip);
                    newMembers.Add(guildMember);
                }

                var memberCharacters = new List <MemberCharacter>();
                try
                {
                    memberCharacters = guildMember.MemberCharacters.ToList();// db.MemberCharacters.Where(x => x.Member_Id.Equals(guildMember.Id)).ToList();
                }
                catch
                {
                }
                string charHtml;

                HtmlDocument docMember = web.Load(charHref);
                try
                {
                    charHtml = docMember.DocumentNode.SelectNodes("//li[@class='media list-group-item p-a collection-char-list']")[0].InnerHtml;
                }
                catch (Exception ex)
                {
                    continue;
                }
                string[]      character      = regexChar.Split(charHtml);
                List <string> listCharacters = character.ToList();

                listCharacters.RemoveAll(x => x.Equals(""));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"row\">"));
                listCharacters.RemoveAll(x => x.Equals("</a>"));
                listCharacters.RemoveAll(x => x.Equals("</div>"));
                listCharacters.RemoveAll(x => x.Equals("</span>"));
                listCharacters.RemoveAll(x => x.Equals("<span class=\"collection-char-gp-label-value\">"));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"collection-char-gp-progress\">"));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"char-portrait-full-gear\"></div>"));
                listCharacters.RemoveAll(x => x.Equals("<span class=\"collection-char-gp-label-percent\">%</span>"));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"collection-char-gp-label\">"));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"collection-char collection-char-light-side\">"));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"collection-char collection-char-dark-side\">"));
                listCharacters.RemoveAll(x => x.Equals("<div class=\"col-xs-6 col-sm-3 col-md-3 col-lg-2\">"));

                var newMemberCharacter = new MemberCharacter
                {
                    Member_Id = guildMember.Id,
                    Id        = Guid.NewGuid()
                };

                foreach (var item in listCharacters)
                {
                    if (item.Contains("<div class=\"char-portrait-full-level"))
                    {
                        newMemberCharacter.Level = Convert.ToInt16(item.Trim().Substring(38, 2).Replace("<", ""));
                    }
                    else if (item.Contains("<div class=\"char-portrait-full-gear-level\">"))
                    {
                        var romanNum = Regex.Replace(item, "(?s).*?(?<=\">)", String.Empty);
                        romanNum = romanNum.Remove(romanNum.IndexOf("</", StringComparison.Ordinal));
                        switch (romanNum)
                        {
                        case "I":
                            newMemberCharacter.Gear = 1;
                            break;

                        case "II":
                            newMemberCharacter.Gear = 2;
                            break;

                        case "III":
                            newMemberCharacter.Gear = 3;
                            break;

                        case "IV":
                            newMemberCharacter.Gear = 4;
                            break;

                        case "V":
                            newMemberCharacter.Gear = 5;
                            break;

                        case "VI":
                            newMemberCharacter.Gear = 6;
                            break;

                        case "VII":
                            newMemberCharacter.Gear = 7;
                            break;

                        case "VIII":
                            newMemberCharacter.Gear = 8;
                            break;

                        case "IX":
                            newMemberCharacter.Gear = 9;
                            break;

                        case "X":
                            newMemberCharacter.Gear = 10;
                            break;

                        case "XI":
                            newMemberCharacter.Gear = 11;
                            break;

                        case "XII":
                            newMemberCharacter.Gear = 12;
                            break;
                        }
                    }
                    else if (item.Contains("<div class=\"collection-char-gp\""))
                    {
                        try
                        {
                            var toConvert = item.Substring(0, item.LastIndexOf('/'));
                            toConvert = toConvert.Substring(toConvert.LastIndexOf('r') + 2);
                            newMemberCharacter.Power = Convert.ToInt32(toConvert.Replace(",", ""));
                        }
                        catch
                        {
                            newMemberCharacter.Power = 0;
                        }
                    }
                    else if (item.Contains("<div class=\"star ") && !item.Contains("star-inactive"))
                    {
                        newMemberCharacter.Stars = Convert.ToInt16(item.Trim().Substring(21, 1));
                    }
                    else if (item.Contains("<img class=\"char-portrait-full-img\""))
                    {
                        var startIndex = item.IndexOf("alt=") + 5;
                        var endIndex   = item.IndexOf("height=") - 2 - startIndex;
                        //string charName = Regex.Replace(item, "<.*?>", String.Empty);
                        string charName = item.Substring(startIndex, endIndex);
                        IEnumerable <Character> charNames = characters.Where(x => x.Name.Equals(charName.Trim())).ToList();

                        if (charNames.Count() == 1)
                        {
                            newMemberCharacter.Character_Id = charNames.FirstOrDefault().Id;
                        }
                        else
                        {
                            if (charName.Contains("Fulcrum"))
                            {
                                newMemberCharacter.Character_Id = charNames.FirstOrDefault(x => x.Name.Equals("Ahsoka Tano (Fulcrum)")).Id;
                            }
                            else if (charName.Equals("Ahsoka Tano") || charName.Equals("hsoka Tano"))
                            {
                                newMemberCharacter.Character_Id = charNames.FirstOrDefault(x => x.Name.Equals("Ahsoka Tano")).Id;
                            }
                            else if (charName.Equals("Jawa"))
                            {
                                newMemberCharacter.Character_Id = charNames.FirstOrDefault(x => x.Name.Equals("Jawa")).Id;
                            }
                            else if (charName.Equals("Han Solo"))
                            {
                                newMemberCharacter.Character_Id = charNames.FirstOrDefault(x => x.Name.Equals("Han Solo")).Id;
                            }
                            else if (charName.Equals("Stormtrooper"))
                            {
                                newMemberCharacter.Character_Id = charNames.FirstOrDefault(x => x.Name.Equals("Stormtrooper")).Id;
                            }
                            else
                            {
                                newMemberCharacter.Character_Id = charNames.FirstOrDefault(x => x.Name.Substring(1).Contains(charName)).Id;
                            }
                        }
                    }
                    else if (item.Contains("<div class=\"collection-char-name\">"))
                    {
                        if (newMemberCharacter.Stars != null)
                        {
                            if (memberCharacters.Any(x => x.Character_Id.Equals(newMemberCharacter.Character_Id)))
                            {
                                MemberCharacter memberCharacterUpdate = memberCharacters.FirstOrDefault(x => x.Character_Id.Equals(newMemberCharacter.Character_Id));

                                memberCharacterUpdate.Level = newMemberCharacter.Level;
                                memberCharacterUpdate.Power = newMemberCharacter.Power;
                                memberCharacterUpdate.Stars = newMemberCharacter.Stars;
                                memberCharacterUpdate.Gear  = newMemberCharacter.Gear;

                                memberCharacters.Remove(memberCharacters.FirstOrDefault(x => x.Character_Id.Equals(newMemberCharacter.Character_Id)));
                                memberCharacters.Add(memberCharacterUpdate);
                            }
                            else
                            {
                                memberCharactersAdd.Add(newMemberCharacter);
                            }
                        }
                        newMemberCharacter = new MemberCharacter
                        {
                            Member_Id = guildMember.Id,
                            Id        = Guid.NewGuid()
                        };
                    }
                }
                if (memberCharacters.Count() != 0)
                {
                    db.BulkUpdate(memberCharacters);
                }
                db = new SwgohDb();
                List <MemberShip> memberShips = db.MemberShips.Where(x => x.Member_Id.Equals(guildMember.Id)).ToList();

                string shipHtml;

                HtmlDocument docShip = web.Load(shipHref);
                try
                {
                    shipHtml = docShip.DocumentNode.SelectNodes("//li[@class='media list-group-item p-a collection-char-list']")[0].InnerHtml;
                }
                catch
                {
                    continue;
                }
                string[]      ship      = regexChar.Split(shipHtml);
                List <string> listShips = ship.ToList();

                listShips.RemoveAll(x => x.Equals(""));
                listShips.RemoveAll(x => x.Equals("<div class=\"row\">"));
                listShips.RemoveAll(x => x.Equals("</a>"));
                listShips.RemoveAll(x => x.Equals("</div>"));
                listShips.RemoveAll(x => x.Equals("</span>"));
                listShips.RemoveAll(x => x.Equals("<span class=\"collection-char-gp-label-value\">"));
                listShips.RemoveAll(x => x.Equals("    \">"));
                listShips.RemoveAll(x => x.Equals("    "));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-ship-primary\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-ship-main\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-ship collection-ship-light-side\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-ship collection-ship-dark-side\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"col-sm-6 col-md-6 col-lg-4\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"ship-portrait-full-frame\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"ship-portrait-full-frame-overlay\"></div>"));
                listShips.RemoveAll(x => x.Equals("<div class=\"ship-portrait-full-frame-image\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-ship-secondary\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-char-gp-progress\">"));
                listShips.RemoveAll(x => x.Equals("<div class=\"collection-char-gp-label\">"));
                listShips.RemoveAll(x => x.Equals("<span class=\"collection-char-gp-label-percent\">%</span>"));
                listShips.RemoveAll(x => x.StartsWith("<div class=\"collection-ship-crew"));
                listShips.RemoveAll(x => x.StartsWith("<div class=\"star star"));
                listShips.RemoveAll(x => x.StartsWith("<div class=\"char-portrait"));

                MemberShip newMemberShip = new MemberShip
                {
                    Member_Id = guildMember.Id,
                    Id        = Guid.NewGuid()
                };

                foreach (var item in listShips)
                {
                    if (item.Contains("<div class=\"ship-portrait-full-frame-level"))
                    {
                        newMemberShip.Level = Convert.ToInt16(item.Trim().Substring(44, 2).Replace("<", ""));
                    }
                    else if (item.Contains("\"Power "))
                    {
                        newMemberShip.Power = item.Trim().Substring(83).Replace("\">", "");
                        try
                        {
                            var toConvert = item.Substring(0, item.LastIndexOf('/'));
                            toConvert = toConvert.Substring(toConvert.LastIndexOf('r') + 2);
                            newMemberShip.ShipPower = Convert.ToInt32(toConvert.Replace(",", ""));
                        }
                        catch
                        {
                            newMemberShip.ShipPower = 0;
                        }
                    }
                    else if (item.Contains("ship-portrait-full-star") && !item.Contains("ship-portrait-full-star-inactive") && !item.Contains("stars"))
                    {
                        if (newMemberShip.Stars == null)
                        {
                            newMemberShip.Stars = 1;
                        }
                        else
                        {
                            newMemberShip.Stars = newMemberShip.Stars + 1;
                        }
                    }
                    else if (item.Contains("<a class=\"collection-ship-name-link\""))
                    {
                        var startIndex = item.IndexOf(">") + 1;
                        var endIndex   = item.IndexOf("</a") - startIndex;
                        //string charName = Regex.Replace(item, "<.*?>", String.Empty);
                        string shipName = item.Substring(startIndex, endIndex);
                        //var shipName = Regex.Replace(item, "<.*?>", string.Empty);
                        IEnumerable <Ship> shipNames = ships.Where(x => x.Name.Equals(shipName.Trim())).ToList();

                        if (shipNames.Count() == 1)
                        {
                            newMemberShip.Ship_Id = shipNames.FirstOrDefault().Id;
                        }
                        else
                        {
                            var blah = 1;
                        }

                        if (newMemberShip.Stars != null)
                        {
                            if (memberShips.Any(x => x.Ship_Id.Equals(newMemberShip.Ship_Id)))
                            {
                                MemberShip memberShipUpdate = memberShips.FirstOrDefault(x => x.Ship_Id.Equals(newMemberShip.Ship_Id));

                                memberShipUpdate.Level     = newMemberShip.Level;
                                memberShipUpdate.Power     = newMemberShip.Power;
                                memberShipUpdate.Stars     = newMemberShip.Stars;
                                memberShipUpdate.ShipPower = newMemberShip.ShipPower;

                                memberShips.Remove(memberShips.FirstOrDefault(x => x.Ship_Id.Equals(newMemberShip.Ship_Id)));
                                memberShips.Add(memberShipUpdate);
                            }
                            else
                            {
                                memberShipsAdd.Add(newMemberShip);
                            }
                        }
                        newMemberShip = new MemberShip
                        {
                            Member_Id = guildMember.Id,
                            Id        = Guid.NewGuid()
                        };
                    }
                }
                if (memberShips.Count != 0)
                {
                    db.BulkUpdate(memberShips);
                }
            }

            db.BulkUpdate(updateMembers);
            db = new SwgohDb();

            db.BulkInsert(newMembers);
            db = new SwgohDb();

            db.BulkInsert(memberCharactersAdd);
            db = new SwgohDb();

            db.BulkInsert(memberShipsAdd);
            db = new SwgohDb();

            var guildUpdate = db.Guilds.Find(id);
            var powers      = db.Members.Where(x => x.Guild_Id == id).ToList();

            guildUpdate.CharacterPower = powers.Sum(x => x.CharacterPower);
            guildUpdate.ShipPower      = powers.Sum(x => x.ShipPower);

            db.Entry(guildUpdate).State = EntityState.Modified;
            db.SaveChanges();
        }