public bool UpdateSubscriber(PlayersExt model)
        {
            bool status = true;

            try
            {
                var mcApi = new MCApi(apiKey, false);
                var merges = GetListOfMerges(model);

                var returnval = mcApi.ListUpdateMember(listId, model.EmailAddress, merges, List.EmailType.Html, true);
            }
            catch (Exception ex)
            {
                //If try to update and didn't found any record so it means it is not already Subscribed.
                //in this case Subscribe the player
                if (IgnoreMailchimpErrors(ex.Message))
                {
                    status = Subscribe(model);
                }
                else
                {
                    ErrorHandling.HandleException(ex);
                    status = false;
                }
            }

            return status;
        }
        public List.Merges GetListOfMerges(PlayersExt model)
        {
            var merge = new List.Merges(model.EmailAddress, List.EmailType.Html)
                    {
                        {"FNAME", model.FirstName},
                        {"LNAME", model.LastName},
                        {"PHONE", model.Mobile},
                        {"DOB", model.DOB},
                        {"MOBNUM", model.Mobile},
                        {"REGDATE", model.RegistrationDate},
                        {"WEIGHT", model.Weight},
                        {"HEIGHT", model.Height},
                        {"AVGACTLEV", model.HowActiveAreYou},
                        {"POSITION", model.PrefferredPosition},
                        {"BMI", model.BMI},
                        {"BODYFAT", model.BodyFat},
                        {"ADDLINE1", model.AddressLine1},
                        {"ADDLINE2", model.AddressLine2},
                        {"CITY", model.City},
                        {"POSTCODE", model.PostCode},
                        {"LEAGUE", model.SelectedLeagueName},

                    };

            return merge;
        }
        public PlayersExt Map_Minimum(Players model)
        {
            PlayersExt tblModel = new PlayersExt()
            {
                PlayerID                  = model.PlayerID,
                TitleID                   = model.TitleID,
                FirstName                 = model.FirstName,
                LastName                  = model.LastName,
                FullName                  = model.FullName,
                EmailAddress              = model.EmailAddress,
                DOB                       = model.DOB,
                Weight                    = model.Weight,
                RegWeight                 = model.Weight,
                Active                    = model.Active,
                Featured                  = model.Featured,
                Mobile                    = model.Mobile,
                HeightID                  = model.HeightID,
                PostCode                  = model.PostCode,
                RegistrationDate          = model.RegistrationDate,
                AdvertisementID           = model.AdvertisementID,
                AdvertisementOther        = model.AdvertisementOther,
                AdvertisementOtherDetails = model.AdvertisementOtherDetails
            };

            return(tblModel);
        }
        public PlayersExt ReadOne_ByEmailAddress(string EmailAddress, bool MapMinimum = false)
        {
            PlayersExt model = null;

            var player = db.Players.Include("Titles").Include("Heights").Include("HowActives").Include("Positions").Include("Advertisements")
                         .Where(m => m.EmailAddress.ToLower() == EmailAddress.ToLower()).FirstOrDefault();

            if (player != null)
            {
                if (MapMinimum)
                {
                    model = Map_Minimum(player);
                }
                else
                {
                    model = Map(player);
                }
            }
            else
            {
                model = null;
            }

            return(model);
        }
예제 #5
0
        //public void UpdateDashboardURLs()
        //{
        //    var playerDashboard = db.PlayerDashboard.Include("Players").ToList();
        //    List<PlayerDashboardExt> ListOfPlayerDashboardExt = new List<PlayerDashboardExt>();

        //    foreach (var item in playerDashboard)
        //    {
        //        PlayerDashboardExt model = Map(item);

        //        List<char> invalidURLChar = SecurityUtils.GetInvalidURLCharacters();

        //        if (item.DashboardURL.Contains(" ") || invalidURLChar.Any(m => item.DashboardURL.Contains(m)))
        //        {
        //            string _DashboardURL = item.DashboardURL;

        //            SecurityUtils.Check_RemoveInvalidURLChar(ref _DashboardURL);

        //            item.DashboardURL = _DashboardURL;
        //            db.SaveChanges();

        //            model.DashboardURL = _DashboardURL;

        //            ListOfPlayerDashboardExt.Add(model);
        //        }
        //    }

        //    //Now Re-Send Email to Each Player, the Standalone Email

        //    MandrillRepository mandrillRepo = new MandrillRepository();

        //    foreach (var item in ListOfPlayerDashboardExt)
        //    {
        //        mandrillRepo.ProgressDashboard_Standalone(item);
        //    }

        //}


        //Create Progress Dashboard for All Player of a League if Enable Progress Dashboard checkbox is ticked for this League
        public void CreateProgressDashboardForSinglePlayer(PlayersExt model)
        {
            try
            {
                PlayerDashboardRepository pdRepo = new PlayerDashboardRepository();

                //Create Premium Dashboard Default Setting for User
                string _DashboardURL = SecurityUtils.EncryptText(model.EmailAddress);

                SecurityUtils.Check_RemoveInvalidURLChar(ref _DashboardURL);

                PlayerDashboardExt modelDashExt = new PlayerDashboardExt()
                {
                    PlayerID             = model.PlayerID,
                    DashboardURL         = _DashboardURL,
                    IsFirstLogin         = true,
                    PlayerFullName       = model.FullName,
                    PlayerEmailAddress   = model.EmailAddress,
                    DashboardCreatedDate = DateTime.Now.Date,
                    DashboardExpiryDate  = DateTime.Now.Date.AddDays(98), //14 Weeks => 14 x 7 = 98 Days
                    ReminderTime         = 19                             //By Default 19:00 when Creating new Player's Dashboard
                };

                string RandomPassword = System.Web.Security.Membership.GeneratePassword(6, 1);
                modelDashExt.DashboardPassword = SecurityUtils.EncryptText(RandomPassword);

                //TODO: Map to DB Object
                var dbmodel = Map(modelDashExt);

                //Save to DB
                db.PlayerDashboard.Add(dbmodel);
                db.SaveChanges();

                //Now Send Email to Each Player, the Standalone Email

                MandrillRepository mandrillRepo = new MandrillRepository();

                mandrillRepo.ProgressDashboard_Standalone(modelDashExt);

                SecurityUtils.AddAuditLog("The Progress Dashboard For Player when Player Added to Team. Success", "For Player Email " + model.EmailAddress);
            }
            catch (Exception ex)
            {
                ErrorHandling.HandleException(ex);

                string ErrorMsg = ex.Message + " - " + ex.InnerException != null ? ex.InnerException.Message : "";
                SecurityUtils.AddAuditLog("The Progress Dashboard For Player when Player Added to Team. Error Occurred", "For Player Email " + model.EmailAddress + " But Error Occurred: " + ErrorMsg);
            }
        }
        public PlayersExt Map(Players model)
        {
            PlayersExt tblModel = new PlayersExt()
            {
                PlayerID     = model.PlayerID,
                TitleID      = model.TitleID,
                Title        = model.Titles.Title,
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                FullName     = model.FullName,
                EmailAddress = model.EmailAddress,
                DOB          = model.DOB,
                Weight       = model.Weight,

                WeightVM = model.Weight,

                Active   = model.Active,
                Featured = model.Featured,

                Mobile   = model.Mobile,
                HeightID = model.HeightID,
                Height   = model.Heights.Height_Display,

                PostCode = model.PostCode,

                Age = (model.Age.HasValue ? model.Age.Value : 0),

                RegistrationDate = model.RegistrationDate,

                AdvertisementID           = model.AdvertisementID,
                AdvertisementOther        = model.AdvertisementOther,
                AdvertisementOtherDetails = model.AdvertisementOtherDetails,
                Advertisement             = model.AdvertisementID.HasValue ? model.Advertisements.Advertisement : ""
                ,
            };

            if (db.PlayerImages.Any(m => m.PlayerID == model.PlayerID && m.DefaultImage == true))
            {
                tblModel.PlayerDefaultImageFileName = db.PlayerImages.FirstOrDefault(m => m.PlayerID == model.PlayerID && m.DefaultImage == true)?.FileName;
            }
            else
            {
                tblModel.PlayerDefaultImageFileName = "";
            }


            return(tblModel);
        }
        public string GenerateHtml_EmergencyContactDetails(SystemSettingsExt sys, PlayersExt player)
        {
            string html = "";

            if (string.IsNullOrEmpty(player.Emergency_ContactName) || string.IsNullOrEmpty(player.Emergency_ContactPhone))
            {
                string EncryptedEmail            = SecurityUtils.EncryptText(player.EmailAddress);
                string _EmergencyContactPageLink = sys.CurrentDomain + "/Home/EmergencyContact?p=" + EncryptedEmail;

                html = "<h2 style='color:red;'>Emergency Contact Details:</h2>" +
                       "<p> As agreed in your terms and conditions all players are required to provide a contact in case of illness or injury. Fill in the form at" +
                       "<a target = '_blank' href = '" + _EmergencyContactPageLink + "'> this link </a> and hit Submit to enable us to finalise your registration. Please ignore this if you've already submitted your Emergency Contact Details.</p>";
            }

            return(html);
        }
        public PlayersExt MapFeatured(Players model)
        {
            PlayersExt tblModel = new PlayersExt()
            {
                PlayerID     = model.PlayerID,
                TitleID      = model.TitleID,
                Title        = model.Titles.Title,
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                FullName     = model.FullName,
                EmailAddress = model.EmailAddress,
                DOB          = model.DOB,
                Weight       = model.Weight,

                WeightVM = model.Weight,

                Active   = model.Active,
                Featured = model.Featured,

                Mobile   = model.Mobile,
                HeightID = model.HeightID,
                Height   = model.Heights.Height_Display,


                PostCode = model.PostCode,

                Age = (model.Age.HasValue ? model.Age.Value : 0),

                PlayerDefaultImageFileName = db.PlayerImages.Any(m => m.PlayerID == model.PlayerID && m.DefaultImage == true) ? db.PlayerImages.FirstOrDefault(m => m.PlayerID == model.PlayerID && m.DefaultImage == true).FileName : ""
            };

            var playerLatestWeight = (from w in db.PlayerWeights
                                      where w.PlayerID == model.PlayerID
                                      orderby w.RecordDate descending
                                      select w).FirstOrDefault();

            if (playerLatestWeight != null)
            {
                tblModel.WeightVM = playerLatestWeight.Weight;
            }



            return(tblModel);
        }
        public void MapUpdate(ref Players dbmodel, PlayersExt model)
        {
            dbmodel.PlayerID     = model.PlayerID;
            dbmodel.TitleID      = model.TitleID;
            dbmodel.FirstName    = model.FirstName;
            dbmodel.LastName     = model.LastName;
            dbmodel.FullName     = model.FullName;
            dbmodel.EmailAddress = model.EmailAddress;
            dbmodel.DOB          = model.DOB;
            dbmodel.Weight       = model.Weight;

            dbmodel.Active   = model.Active;
            dbmodel.Featured = model.Featured;

            dbmodel.Mobile   = model.Mobile;
            dbmodel.HeightID = model.HeightID;

            dbmodel.PostCode = model.PostCode;
        }
        public bool Subscribe_NonPaidPlayers(PlayersExt model)
        {
            bool status = true;

            try
            {
                var mcApi = new MCApi(apiKey, false);

                //var lists = mcApi.Lists();

                //foreach (var item in lists.Data)
                //{
                //    string listID = item.ListID;
                //}

                List<List.Merges> SubscriptionInfo = new List<List.Merges>();

                var SubscriptionOptions = new MailChimp.Types.List.SubscribeOptions();
                SubscriptionOptions.DoubleOptIn = false;
                SubscriptionOptions.ReplaceInterests = false;
                SubscriptionOptions.EmailType = List.EmailType.Html;
                SubscriptionOptions.SendWelcome = false;
                SubscriptionOptions.UpdateExisting = true;

                var merges = GetListOfMerges(model);

                var returnvalue = mcApi.ListSubscribe(NonPaidPlayers_ListId, model.EmailAddress, merges, SubscriptionOptions);
            }
            catch (Exception ex)
            {
                if (IgnoreMailchimpErrors(ex.Message))
                { }
                else
                {
                    ErrorHandling.HandleException(ex);
                    status = false;
                }
            }

            return status;
        }
        /*
         * public bool SendActivationEMail(out string errorMsg)
         * {
         *  string activationLink = "http://usmanchohan.co.uk";
         *  //HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Register/Activation.aspx?id=" + ts.Id;
         *
         *  //send-template(string key, string template_name, array template_content, struct message)
         *  dynamic sendParams = new ExpandoObject();
         *  sendParams.key = "Z46-URL8pJppuh8Hv5Ff3A";
         *  sendParams.template_name = "Secret Project Trial Activation";
         *
         *  sendParams.template_content = new List<dynamic>();
         *
         *  sendParams.message = new ExpandoObject();
         *  sendParams.message.subject = "Here's your Secret Project activation email";
         *  sendParams.message.from_email = "*****@*****.**";
         *  sendParams.message.from_name = "Secret Project";
         *
         *  sendParams.message.to = new List<dynamic>();
         *  sendParams.message.to.Add(new ExpandoObject());
         *  sendParams.message.to[0].email = "*****@*****.**";
         *  sendParams.message.to[0].name = "Usman Akram";
         *
         *  sendParams.message.track_opens = true;
         *  //sendParams.message.track_clicks = true;
         *
         *  sendParams.message.global_merge_vars = new List<dynamic>();
         *  sendParams.message.global_merge_vars.Add(new ExpandoObject());
         *  sendParams.message.global_merge_vars[0].name = "NAME";
         *  sendParams.message.global_merge_vars[0].content = "Chohan";
         *
         *  sendParams.message.global_merge_vars.Add(new ExpandoObject());
         *  sendParams.message.global_merge_vars[1].name = "LINK";
         *  sendParams.message.global_merge_vars[1].content = activationLink;
         *
         *  errorMsg = string.Empty;
         *
         *  MandrillError merr = SendMessage(sendParams);
         *
         *  switch (merr)
         *  {
         *      case MandrillError.OK:
         *          return true;
         *
         *      case MandrillError.WebException:
         *      case MandrillError.HttpNotOk:
         *          errorMsg = "There was an issue sending your activation e-mail. Please try again later or call us directly.";
         *          break;
         *
         *      case MandrillError.Invalid:
         *          errorMsg = "Your email address appears to be invalid. Please try again with a valid address, or call us directly.";
         *          break;
         *
         *      case MandrillError.Rejected:
         *          errorMsg = "Your activation email was rejected. Please try again with a valid address, or call us directly.";
         *          break;
         *
         *      case MandrillError.Unknown:
         *          errorMsg = "There was an unknown problem sending your activation email. Please try again, or call us directly.";
         *          break;
         *  }
         *  return false;
         * }
         */

        #endregion Testing Template

        public bool SendRegistrationEmail(PlayersExt model, Controller ctrl)
        {
            SystemSettingsRepository sysRepo = new SystemSettingsRepository();
            var sys = sysRepo.GetSystemSettings();
            //Add this Postfix if it is a TESTING Site.
            string TestSitePostfix = (sys.CurrentDomain.Contains("test") || sys.CurrentDomain.Contains("localhost")) ? "_TestSite" : "";

            dynamic sendParams = new ExpandoObject();

            sendParams.template_name = "tmpRegistration_PlannedLeagueCOPY" + TestSitePostfix;


            // string LeagueHomePage = sys.CurrentDomain + "/" + league.NewsTag;
            string ReferralPageLink = sys.CurrentDomain + "/Refer/" + model.ReferralCode;
            string ReferralLink     = sys.CurrentDomain + "/refercode/" + model.ReferralCode;

            sendParams.template_content = new List <dynamic>();

            sendParams.message         = new ExpandoObject();
            sendParams.message.subject = "Welcome to MAN v FAT Football";
            sendParams.message.to      = new List <dynamic>();
            sendParams.message.to.Add(new ExpandoObject());
            sendParams.message.to[0].email = model.EmailAddress;
            sendParams.message.to[0].name  = model.FullName;

            //sendParams.message.track_opens = true;
            //sendParams.message.track_clicks = true;

            sendParams.message.global_merge_vars = new List <dynamic>();

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[0].name    = "BMI";
            sendParams.message.global_merge_vars[0].content = model.BMI.HasValue ? model.BMI.Value.ToString("N2") : "";

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[1].name    = "BODYFAT";
            sendParams.message.global_merge_vars[1].content = model.BodyFat.HasValue ? model.BodyFat.Value.ToString("N2") : "";

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[2].name    = "LEAGUEHOMEPAGE";
            sendParams.message.global_merge_vars[2].content = //LeagueHomePage;

                                                              sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[3].name    = "WHATSAPPGROUP";
            sendParams.message.global_merge_vars[3].content = //WhatsAppGroupLink;

                                                              sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[4].name    = "MSGNOEMERGENCYDETAILS";
            sendParams.message.global_merge_vars[4].content = GenerateHtml_EmergencyContactDetails(sys, model);

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[5].name    = "REFERRALPAGELINK";
            sendParams.message.global_merge_vars[5].content = ReferralPageLink;

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[6].name    = "REFERRALLINK";
            sendParams.message.global_merge_vars[6].content = ReferralLink;

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[7].name    = "REFERRALCODE";
            sendParams.message.global_merge_vars[7].content = model.ReferralCode;

            ////Get Premium Dashboard Payment Link
            //PlayerPaymentsRepository playerPaymentsRepo = new PlayerPaymentsRepository();
            //var payment = playerPaymentsRepo.GetPremiumDashboardPayment(model.PlayerID, ctrl);

            //sendParams.message.global_merge_vars.Add(new ExpandoObject());
            //sendParams.message.global_merge_vars[5].name = "PAYLINKDASHBOARD";
            //sendParams.message.global_merge_vars[5].content = payment != null ? SecurityUtils.GeneratePayLinkURL(payment.PaylinkID) : "";

            MandrillError merr     = SendMessage(sendParams, sys);
            string        errorMsg = "";

            switch (merr)
            {
            case MandrillError.OK:
                SecurityUtils.AddAuditLog("Mandrill Email Success", "\"Registration Email\" Email Sent To PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress);
                return(true);

            case MandrillError.WebException:
            case MandrillError.HttpNotOk:
                errorMsg = "There was an issue sending your activation e-mail. Please try again later or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Attempt to Send Email To = PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress + " - HttpNotOK: " + errorMsg);
                break;

            case MandrillError.Invalid:
                errorMsg = "Your email address appears to be invalid. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Invalid: " + errorMsg);
                break;

            case MandrillError.Rejected:
                errorMsg = "Your activation email was rejected. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Rejected: " + errorMsg);
                break;

            case MandrillError.Unknown:
                errorMsg = "There was an unknown problem sending your activation email. Please try again, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Unknown: " + errorMsg);
                break;
            }
            return(false);
        }
        public bool SendForgottenPassword_Email(PlayersExt model, string ResetPasswordLink)
        {
            //
            SystemSettingsRepository sysRepo = new SystemSettingsRepository();
            var sys = sysRepo.GetSystemSettings();
            //Add this Postfix if it is a TESTING Site.
            string TestSitePostfix = (sys.CurrentDomain.Contains("test") || sys.CurrentDomain.Contains("localhost")) ? "_TestSite" : "";

            dynamic sendParams = new ExpandoObject();

            sendParams.template_name = "ForgottenPassword" + TestSitePostfix;

            sendParams.template_content = new List <dynamic>();

            sendParams.message         = new ExpandoObject();
            sendParams.message.subject = "MANvFAT Football Forgotten Password";
            sendParams.message.to      = new List <dynamic>();
            sendParams.message.to.Add(new ExpandoObject());
            sendParams.message.to[0].email = model.EmailAddress;
            sendParams.message.to[0].name  = model.FullName;

            //sendParams.message.track_opens = true;
            //sendParams.message.track_clicks = true;

            sendParams.message.global_merge_vars = new List <dynamic>();

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[0].name    = "RESETPASSWORDLINK";
            sendParams.message.global_merge_vars[0].content = ResetPasswordLink;

            MandrillError merr     = SendMessage(sendParams, sys);
            string        errorMsg = "";

            switch (merr)
            {
            case MandrillError.OK:
                SecurityUtils.AddAuditLog("Mandrill Email Success", "\"Forgotten Password Email\" Email Sent To PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress);
                return(true);

            case MandrillError.WebException:
            case MandrillError.HttpNotOk:
                errorMsg = "There was an issue sending your activation e-mail. Please try again later or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", " \"Forgotten Password Email\" Attempt to Send Email To = PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress + " - HttpNotOK: " + errorMsg);
                break;

            case MandrillError.Invalid:
                errorMsg = "Your email address appears to be invalid. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Forgotten Password Email\" Invalid: " + errorMsg);
                break;

            case MandrillError.Rejected:
                errorMsg = "Your activation email was rejected. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Forgotten Password Email\" Rejected: " + errorMsg);
                break;

            case MandrillError.Unknown:
                errorMsg = "There was an unknown problem sending your activation email. Please try again, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Forgotten Password Email\" Unknown: " + errorMsg);
                break;
            }
            return(false);
        }
        /// <summary>
        /// Add the Action to Audit Log
        /// </summary>
        /// <param name="model">The Object for which this Auditlog took place</param>
        /// <param name="Action">"Added New User OR Updated User Details OR Deleted User"</param>

        private void AuditLog(Controller ctrl, AuditAction auditAction, PlayersExt dbmodel = null, PlayersExt model = null, string CustomMsg = "")
        {
            string AuditLogShortDesc = "", AuditLogLongDesc = "";

            //StringBuilder sb = new StringBuilder();

            if (auditAction == AuditAction.Create) //Creating new Record
            {
                AuditLogShortDesc = AuditLogLongDesc = "New Player has been Added/Registered " + CustomMsg + " Email = " + dbmodel.EmailAddress;

                //sb.Append("<table class='table table-stripped auditLogStyle'>");
                //sb.Append("<tr><th colspan='2'>New User has been Added</th></tr>");
                //sb.Append("<tr><th>Full Name</th><td>" + dbmodel.FullName + "</td></tr>");
                //sb.Append("<tr><th>Email</th><td>" + dbmodel.EmailAddress + "</td></tr>");
                //sb.Append("<tr><th>Role</th><td>" + dbmodel.Role + "</td></tr>");
                //sb.Append("<tr><th>Locked</th><td>" + dbmodel.Locked + "</td></tr>");
                //sb.Append("<tr><th>Deleted</th><td>" + dbmodel.Deleted + "</td></tr>");
                //sb.Append("</table>");

                //AuditLogLongDesc = sb.ToString();
            }
            else if (auditAction == AuditAction.Update)
            {
                AuditLogShortDesc = AuditLogLongDesc = "Player has been Updated " + CustomMsg + " Email = " + dbmodel.EmailAddress;

                //sb.Append("<table class='table table-stripped auditLogStyle'>");

                //sb.Append("<tr><th colspan='2'>User has been Updated</th></tr>");
                //sb.Append("<tr><th colspan='2'><label>BEFORE</label></th></tr>");

                //sb.Append("<tr><th>Full Name</th><td>" + dbmodel.FullName + "</td></tr>");
                //sb.Append("<tr><th>Email</th><td>" + dbmodel.EmailAddress + "</td></tr>");
                //sb.Append("<tr><th>Role</th><td>" + dbmodel.Role + "</td></tr>");
                //sb.Append("<tr><th>Locked</th><td>" + dbmodel.Locked + "</td></tr>");
                //sb.Append("<tr><th>Deleted</th><td>" + dbmodel.Deleted + "</td></tr>");

                //sb.Append("<tr><th colspan='2'><label>AFTER</label></th></tr>");

                //sb.Append("<tr><th>Full Name</th><td>" + dbmodel.FullName + "</td></tr>");
                //sb.Append("<tr><th>Email</th><td>" + dbmodel.EmailAddress + "</td></tr>");
                //sb.Append("<tr><th>Role</th><td>" + dbmodel.Role + "</td></tr>");
                //sb.Append("<tr><th>Locked</th><td>" + dbmodel.Locked + "</td></tr>");
                //sb.Append("<tr><th>Deleted</th><td>" + dbmodel.Deleted + "</td></tr>");

                //sb.Append("</table>");

                //AuditLogLongDesc = sb.ToString();
            }
            else if (auditAction == AuditAction.Delete)
            {
                AuditLogShortDesc = AuditLogLongDesc = "Player has been Deleted " + CustomMsg + " Email = " + model.EmailAddress;

                //sb.Append("<tr><th>Full Name</th><td>" + dbmodel.FullName + "</td></tr>");
                //sb.Append("<tr><th>Email</th><td>" + dbmodel.EmailAddress + "</td></tr>");
                //sb.Append("<tr><th>Role</th><td>" + dbmodel.Role + "</td></tr>");
                //sb.Append("<tr><th>Locked</th><td>" + dbmodel.Locked + "</td></tr>");
                //sb.Append("<tr><th>Deleted</th><td>" + dbmodel.Deleted + "</td></tr>");

                //sb.Append("</table>");

                //AuditLogLongDesc = sb.ToString();
            }

            SecurityUtils.AddAuditLog(AuditLogShortDesc, AuditLogLongDesc, ctrl);
        }
        public long CreateOrUpdate(ref PlayersExt model, ref string Msg, ref bool status, Controller ctrl, bool AddTo_NoTeamPlayers = false, long?RegPlayerLeagueID = null)
        {
            long PlayerID = model.PlayerID;

            try
            {
                if (model.PlayerID == 0)
                {
                    model.AdvertisementOther = (model.AdvertisementID == 15);
                    //Create New Referral Code for this New Player

                    model.ReferralCode = SecurityUtils.GenerateUniqueReferralCode();

                    //TODO: Map to DB Object
                    model.RegistrationDate = DateTime.Now;
                    var dbmodel = Map(model);

                    //TODO: Save DB Changes and Set the Return Primary Key ID
                    db.Players.Add(dbmodel);
                    db.SaveChanges();

                    /*There's a Insert Trigger on Player's Table which do the following when new Player Added
                     *
                     * 1. Insert Player into PlayerWeightWeeks table with Just Player ID
                     * 2. Check if there's any Facebook Lead player with same Email Address, If Exists then delete the record
                     * 3. Check if the Player with Same Email Address Already Exists in Player's Archive then Delete the Record from Player Archive
                     */


                    PlayerID = dbmodel.PlayerID;

                    /**Get how many players Teamed+NonTeamed are singed up for this league**/
                    //NAGsRepository nagRepo = new NAGsRepository();
                    //nagRepo.TriggerNAGForXPlayers(RegPlayerLeagueID.Value, ctrl, ref Msg, ref status);

                    Msg = "New Player Record Created Successfully";

                    //TOD: Add to Audit Log
                    //  var playerExt = ReadOne(dbmodel.PlayerID);
                    //AuditLog(ctrl, AuditAction.Create, playerExt, null);

                    /***MailChimp***/

                    //Whenever new Player Added into DB then add it to MailChimp
                    // MailChimpRepository mcRepo = new MailChimpRepository();
//mcRepo.Subscribe(playerExt);
                }
                else
                {
                    //Update Existing Record
                    var dbmodel = db.Players.FirstOrDefault(p => p.PlayerID == PlayerID);


                    var ForAuditLog = Map(dbmodel);


                    //TODO: Map to DB Object
                    MapUpdate(ref dbmodel, model);
                    //TODO: Update DB Changes
                    db.SaveChanges();
                    PlayerID = dbmodel.PlayerID;



                    Msg = "Player Record Updated Successfully";
                    //TOD: Add to Audit Log
                    var playerExt = ReadOne(dbmodel.PlayerID);
                    AuditLog(ctrl, AuditAction.Update, ForAuditLog, playerExt);

#if Debug == false
                    /***MailChimp***/
                    //Whenever new Player Updated into DB then Update its record in MailChimp
                    MailChimpRepository mcRepo = new MailChimpRepository();
                    mcRepo.UpdateSubscriber(playerExt);
#endif
                }
            }
            catch (Exception ex)
            {
                Msg    = ErrorHandling.HandleException(ex);
                status = false;
            }

            return(PlayerID);
        }