public PlayerDashboardExt Map(PlayerDashboard model) { PlayerDashboardExt tblModel = new PlayerDashboardExt() { PlayerDashboardID = model.PlayerDashboardID, PlayerID = model.PlayerID, PlayerFullName = model.Players.FullName, PlayerEmailAddress = model.Players.EmailAddress, PlayerHeight_cm = model.Players.Heights.Height_Value, IsPlayerActive = model.Players.Active, DashboardURL = model.DashboardURL, DashboardPassword = SecurityUtils.DecryptCypher(model.DashboardPassword), TargetWeight = model.TargetWeight, PasswordResetCode = model.PasswordResetCode, ResetCodeExpiry = model.ResetCodeExpiry, Locked = model.Locked, Deleted = model.Deleted, IsFirstLogin = model.IsFirstLogin, LoginSessionID = model.LoginSessionID, DashboardCreatedDate = model.DashboardCreatedDate, DashboardExpiryDate = model.DashboardExpiryDate, //Share Data Settings ShareDataFrequency = model.ShareDataFrequency, ShareDataWith = model.ShareDataWith, DayOfWeek = model.DayOfWeek, AdditionalRecipients = model.AdditionalRecipients, OptionalMessage = model.OptionalMessage, LastSentDate = model.LastSentDate, ReminderTime = model.ReminderTime }; return(tblModel); }
public bool ValidateLogin(PlayerDashboardExt playerDashboard, Controller ctrl, ref string Reason) { bool IsValid = false; DateTime TodayDate = DateTime.Now.Date; if (playerDashboard != null) { CookiesRespository cookie = new CookiesRespository(); var LoginCookie = cookie.GetDashboardLoginCookie(ctrl); if (string.IsNullOrEmpty(LoginCookie.LoginSessionID) == false && string.IsNullOrEmpty(playerDashboard.LoginSessionID) == false && LoginCookie.LoginSessionID == playerDashboard.LoginSessionID && playerDashboard.DashboardExpiryDate >= TodayDate && playerDashboard.IsPlayerActive == true) { IsValid = true; } } if (IsValid == false && (playerDashboard.DashboardExpiryDate >= TodayDate) == false) { Reason = "Your Premium Membership has been Expired."; } else if (IsValid == false && playerDashboard.IsPlayerActive == false) { Reason = "Your status as a MANvFAT Player is not Active."; } return(IsValid); }
public PlayerDashboard Map(PlayerDashboardExt model) { PlayerDashboard tblModel = new PlayerDashboard() { PlayerDashboardID = model.PlayerDashboardID, PlayerID = model.PlayerID, DashboardURL = model.DashboardURL, DashboardPassword = model.DashboardPassword, TargetWeight = model.TargetWeight, PasswordResetCode = model.PasswordResetCode, ResetCodeExpiry = model.ResetCodeExpiry, Locked = model.Locked, Deleted = model.Deleted, IsFirstLogin = model.IsFirstLogin, LoginSessionID = model.LoginSessionID, DashboardCreatedDate = model.DashboardCreatedDate, DashboardExpiryDate = model.DashboardExpiryDate, //Share Data Settings ShareDataFrequency = model.ShareDataFrequency, ShareDataWith = model.ShareDataWith, DayOfWeek = model.DayOfWeek, AdditionalRecipients = model.AdditionalRecipients, OptionalMessage = model.OptionalMessage, LastSentDate = model.LastSentDate, ReminderTime = model.ReminderTime }; return(tblModel); }
public bool Delete(PlayerDashboardExt model, ref string Msg, Controller ctrl) { bool status = true; //TODO: Get Current Object from DB var ItemToDelete = db.PlayerDashboard.Include("Players").FirstOrDefault(m => m.PlayerID == model.PlayerID); try { if (ItemToDelete != null) { var ForAudiLog = Map(ItemToDelete); //TODO: Check if it is not null, then Remove from DB db.PlayerDashboard.Remove(ItemToDelete); db.SaveChanges(); //Add To Log AuditLog(ctrl, AuditAction.Delete, null, ForAudiLog); } } catch (Exception ex) { Msg = ErrorHandling.HandleException(ex); status = false; } return(status); }
//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 void MapUpdate(ref PlayerDashboard dbmodel, PlayerDashboardExt model) { dbmodel.PlayerID = model.PlayerID; dbmodel.DashboardURL = model.DashboardURL; dbmodel.DashboardPassword = SecurityUtils.EncryptText(model.DashboardPassword); dbmodel.IsFirstLogin = false; dbmodel.TargetWeight = model.TargetWeight; dbmodel.Locked = model.Locked; dbmodel.Deleted = model.Deleted; //Share Data Settings dbmodel.ShareDataFrequency = model.ShareDataFrequency; dbmodel.ShareDataWith = model.ShareDataWith; dbmodel.DayOfWeek = model.DayOfWeek; dbmodel.AdditionalRecipients = model.AdditionalRecipients; dbmodel.OptionalMessage = model.OptionalMessage; dbmodel.ReminderTime = model.ReminderTime; }
/// <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, PlayerDashboardExt dbmodel = null, PlayerDashboardExt model = null) { string AuditLogShortDesc = "", AuditLogLongDesc = ""; StringBuilder sb = new StringBuilder(); if (auditAction == AuditAction.Create) //Creating new Record { AuditLogShortDesc = AuditLogLongDesc = "New Player Dashboard has been Added PlayerID = " + dbmodel.PlayerID + " DashboardURL = " + dbmodel.DashboardURL; } else if (auditAction == AuditAction.Update) { AuditLogShortDesc = AuditLogLongDesc = "Player Dashboard has been Updated PlayerID = " + model.PlayerID + " DashboardURL = " + model.DashboardURL; } else if (auditAction == AuditAction.Delete) { AuditLogShortDesc = AuditLogLongDesc = "Player Dashboard has been Deleted PlayerID = " + model.PlayerID + " DashboardURL = " + model.DashboardURL; } SecurityUtils.AddAuditLog(AuditLogShortDesc, AuditLogLongDesc, ctrl); }
public bool CreateOrUpdate(PlayerDashboardExt model, ref string Msg, Controller ctrl) { bool status = true; if (model.PlayerDashboardID == 0) { try { string RandomPassword = System.Web.Security.Membership.GeneratePassword(6, 1); model.DashboardPassword = SecurityUtils.EncryptText(RandomPassword); //TODO: Map to DB Object var dbmodel = Map(model); //TODO: Save DB Changes and Set the Return Primary Key ID db.PlayerDashboard.Add(dbmodel); db.SaveChanges(); //TOD: Add to Audit Log AuditLog(ctrl, AuditAction.Create, model, null); } catch (Exception ex) { Msg = ErrorHandling.HandleException(ex); status = false; } } else { try { var dbmodel = db.PlayerDashboard.Include("Players").FirstOrDefault(p => p.PlayerDashboardID == model.PlayerDashboardID); var proceedToSave = true; //Validate Dashboard URL ValidateDashboardURL(dbmodel.DashboardURL, model.DashboardURL, ref Msg, ref status); if (!string.IsNullOrEmpty(model.DashboardPassword)) { if (SecurityUtils.DecryptCypher(dbmodel.DashboardPassword).Equals(model.DashboardPassword)) { status = false; Msg = "New Password shouldn't be same as your previous Password"; } } else { model.DashboardPassword = SecurityUtils.DecryptCypher(dbmodel.DashboardPassword); } proceedToSave = status; if (proceedToSave) { var ForAuditLog = Map(dbmodel); //TODO: Map to DB Object MapUpdate(ref dbmodel, model); //TODO: Update DB Changes db.SaveChanges(); //TOD: Add to Audit Log AuditLog(ctrl, AuditAction.Update, ForAuditLog, model); } } catch (Exception ex) { Msg = ErrorHandling.HandleException(ex); status = false; } } return(status); }
public bool ProgressDashboard_Standalone(PlayerDashboardExt model) { SystemSettingsRepository sysRepo = new SystemSettingsRepository(); var sys = sysRepo.GetSystemSettings(); var DashboardURL = sys.CurrentDomain + "/Member/" + model.DashboardURL; //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 = "ProgressDashboard_Standalone" + TestSitePostfix; sendParams.template_content = new List <dynamic>(); sendParams.message = new ExpandoObject(); sendParams.message.subject = "Your Progress Dashboard at MAN v FAT Football"; sendParams.message.to = new List <dynamic>(); sendParams.message.to.Add(new ExpandoObject()); sendParams.message.to[0].email = model.PlayerEmailAddress; sendParams.message.to[0].name = model.PlayerFullName; //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 = "PROGRESSDASHLINK"; sendParams.message.global_merge_vars[0].content = DashboardURL; sendParams.message.global_merge_vars.Add(new ExpandoObject()); sendParams.message.global_merge_vars[1].name = "PROGRESSDASHPASS"; sendParams.message.global_merge_vars[1].content = SecurityUtils.DecryptCypher(model.DashboardPassword); MandrillError merr = SendMessage(sendParams, sys); string errorMsg = ""; switch (merr) { case MandrillError.OK: SecurityUtils.AddAuditLog("Mandrill Email Success", "\"ProgressDashboard_Standalone\" Email Sent To PlayerID: " + model.PlayerID + " Email = " + model.PlayerEmailAddress); 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", "\"ProgressDashboard_Standalone\" Attempt to Send Email To = PlayerID: " + model.PlayerID + " Email = " + model.PlayerEmailAddress + " - 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", "\"ProgressDashboard_Standalone\" 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", "\"ProgressDashboard_Standalone\" 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", "\"ProgressDashboard_Standalone\" Unknown: " + errorMsg); break; } return(false); }