protected void btnWelcome_Click(object sender, EventArgs e) { Users users = new Users(UserSession.LoginUser); users.LoadByUserID(_userID); EmailPosts.SendWelcomeNewSignup(UserSession.LoginUser, _userID, ""); _manager.Alert("A welcome message has been sent to " + users[0].FirstName + " " + users[0].LastName); }
public static string GetEmailPost(RestCommand command, int emailPostID) { EmailPost emailPost = EmailPosts.GetEmailPost(command.LoginUser, emailPostID); if (emailPost.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(emailPost.GetXml("EmailPost", true)); }
public void RequestTicketUpdate(int ticketID) { TicketsViewItem ticket = TicketsView.GetTicketsViewItem(UserSession.LoginUser, ticketID); if (ticket == null) { return; } EmailPosts.SendTicketUpdateRequest(UserSession.LoginUser, ticketID); string description = String.Format("{0} requested an update from {1} for {2}", UserSession.CurrentUser.FirstLastName, ticket.UserName, Tickets.GetTicketLink(UserSession.LoginUser, ticketID)); ActionLogs.AddActionLog(UserSession.LoginUser, ActionLogType.Update, ReferenceType.Tickets, ticket.TicketID, description); }
public static string GetEmailPosts(RestCommand command) { EmailPosts emailPosts = new EmailPosts(command.LoginUser); emailPosts.LoadByOrganizationID(command.Organization.OrganizationID); if (command.Format == RestFormat.XML) { return(emailPosts.GetXml("EmailPosts", "EmailPost", true, command.Filters)); } else { throw new RestException(HttpStatusCode.BadRequest, "Invalid data format"); } }
public static string ChangePW(string password, string confirm, string sessionID) { if (TSAuthentication.SessionID != sessionID) { return("Unable to authenticate your session. Please refresh the page and try again."); } bool result = false; StringBuilder builder = new StringBuilder("<ul>"); if (password.Trim() != confirm.Trim()) { builder.Append("<li>Your passwords do not match.</li>"); result = true; } if (password.Trim().Length < 6) { builder.Append("<li>Please choose a password that is at least 6 characters long.</li>"); result = true; } builder.Append("</ul"); if (!result) { Users users = new Users(TSAuthentication.GetLoginUser()); users.LoadByUserID(TSAuthentication.UserID); if (!users.IsEmpty) { users[0].CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); users[0].IsPasswordExpired = false; users[0].PasswordCreatedUtc = DateTime.UtcNow; users.Save(); EmailPosts.SendChangedTSPassword(users.LoginUser, users[0].UserID); } return(""); } else { return(builder.ToString()); } }
protected void btnReset_Click(object sender, EventArgs e) { Users users = new Users(UserSession.LoginUser); users.LoadByUserID(_userID); if (!users.IsEmpty) { if (users[0].CryptedPassword == "") { string password = DataUtils.GenerateRandomPassword(); users[0].CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); users[0].IsPasswordExpired = true; users[0].Collection.Save(); if (UserSession.CurrentUser.IsTSUser) { EmailPosts.SendWelcomeTSUser(UserSession.LoginUser, users[0].UserID, password); } else { EmailPosts.SendWelcomePortalUser(UserSession.LoginUser, users[0].UserID, password); } _manager.Alert("A new password has been sent to " + users[0].FirstName + " " + users[0].LastName); return; } else { if (DataUtils.ResetPassword(UserSession.LoginUser, users[0], !UserSession.CurrentUser.IsTSUser)) { _manager.Alert("A new password has been sent to " + users[0].FirstName + " " + users[0].LastName); return; } } } _manager.Alert("There was an error sending the password."); }
private static SignInResult IsValid(LoginUser loginUser, string email, string password, int organizationId, ref User user, ref Organization organization) { SignInResult validation = new SignInResult(); organization = Organizations.GetOrganization(loginUser, organizationId); bool isNewSignUp = DateTime.UtcNow.Subtract(organization.DateCreatedUtc).TotalMinutes < 10; if (!organization.IsActive) { if (string.IsNullOrEmpty(organization.InActiveReason)) { validation.Error = "Your account is no longer active. Please contact TeamSupport.com."; validation.Result = LoginResult.Fail; } else { validation.Error = "Your company account is no longer active.<br />" + organization.InActiveReason; validation.Result = LoginResult.Fail; } TSEventLog.WriteEvent(TSEventLogEventType.FailedLoginAttempt, HttpContext.Current.Request, null, organization, new string[] { "Email: " + email }); return(validation); } Users users = new Users(loginUser); users.LoadByEmail(1, email); if (users.Count == 1) { user = users[0]; } else { foreach (User u in users) { if (u.OrganizationID == organizationId) { user = u; break; } } } int attempts = LoginAttempts.GetAttemptCount(loginUser, user.UserID, 15); validation.LoginFailedAttempts = attempts; if (user != null && attempts <= MAXLOGINATTEMPTS) { validation.UserId = user.UserID; validation.OrganizationId = user.OrganizationID; if (IsSupportImpersonation(password)) { _skipVerification = true; validation.Result = LoginResult.Success; validation.Error = string.Empty; //vv Log this information! } else { if (user.CryptedPassword != EncryptPassword(password) && user.CryptedPassword != password && !isNewSignUp) { validation.Error = "Invalid email or password."; validation.Result = LoginResult.Fail; } if (!organization.IsActive) { if (string.IsNullOrEmpty(organization.InActiveReason)) { validation.Error = "Your account is no longer active. Please contact TeamSupport.com."; validation.Result = LoginResult.Fail; } else { validation.Error = "Your company account is no longer active.<br />" + organization.InActiveReason; validation.Result = LoginResult.Fail; } } if (!user.IsActive) { validation.Error = "Your account is no longer active.   Please contact your administrator."; validation.Result = LoginResult.Fail; } DateTime passwordCreatedDate = user.PasswordCreatedUtc != null ? (DateTime)user.PasswordCreatedUtc : user.DateCreated; if (validation.Result != LoginResult.Fail && user.IsPasswordExpired || (organization.DaysBeforePasswordExpire > 0 && DateTime.UtcNow > passwordCreatedDate.AddDays(organization.DaysBeforePasswordExpire))) { validation.Error = "Your password has expired."; validation.Result = LoginResult.PasswordExpired; } } } else if (user == null) { validation.Error = "Invalid email or password."; validation.Result = LoginResult.Fail; } else { validation.Error = string.Format("Your account is temporarily locked, because of too many failed login attempts.{0}Try again in 15 minutes or use the forgot password link above to reset your password. ", Environment.NewLine); validation.Result = LoginResult.Fail; if (attempts == MAXLOGINATTEMPTS + 1) { TSEventLog.WriteEvent(TSEventLogEventType.AccountLocked, HttpContext.Current.Request, user, organization); EmailPosts.SendTooManyAttempts(loginUser, user.UserID); } } if (validation.Result != LoginResult.Success && validation.Result != LoginResult.Unknown && !string.IsNullOrEmpty(validation.Error)) { TSEventLog.WriteEvent(TSEventLogEventType.FailedLoginAttempt, HttpContext.Current.Request, user, organization, new string[] { "Attempted Email: " + email }); LoginAttempts.AddAttempt(loginUser, user.UserID, false, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser, HttpContext.Current.Request.UserAgent, GetDeviceID()); } else { TSEventLog.WriteEvent(TSEventLogEventType.LoginSuccess, HttpContext.Current.Request, user, organization); validation.Result = LoginResult.Success; } return(validation); }
public string[] SavePassword(int userID, string token, string pw1, string pw2) { List <string> result = new List <string>(); if (pw1 != pw2) { result.Add("Passwords do not match."); } if (!pw1.Any(char.IsUpper)) { result.Add("At least one uppercase letter is required."); } if (!pw1.Any(char.IsLower)) { result.Add("At least one lowercase letter is required."); } if (!pw1.Any(char.IsDigit)) { result.Add("At least one number is required."); } if (pw1.Length < 8) { result.Add("Use at least 8 characters."); } if (pw1.Length > 20) { result.Add("Use less than 20 characters."); } if (result.Count < 1) { User user = null; if (TSAuthentication.Ticket != null) { user = Users.GetUser(TSAuthentication.GetLoginUser(), TSAuthentication.UserID); } else { user = Users.GetUser(LoginUser.Anonymous, userID); if (user.CryptedPassword != token && user.CryptedPassword != FormsAuthentication.HashPasswordForStoringInConfigFile(token, "MD5")) { user = null; } } if (user != null) { user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(pw1, "MD5"); user.IsPasswordExpired = false; user.PasswordCreatedUtc = DateTime.UtcNow; user.Collection.Save(); EmailPosts.SendChangedTSPassword(LoginUser.Anonymous, user.UserID); } else { result.Add("There was an issue saving your password. Please try resetting your password again."); } } return(result.ToArray()); }
public string CodeVerification(int userId, string codeEntered) { SignInResult result = new SignInResult(); LoginUser loginUser = LoginUser.Anonymous; try { Users users = new Users(loginUser); users.LoadByUserID(userId); result.UserId = userId; if (users.Count > 0) { result.OrganizationId = users[0].OrganizationID; string codeSent = users[0].verificationCode; codeEntered = codeEntered.Trim(); codeEntered = codeEntered.Replace(" ", string.Empty); if (codeSent == codeEntered) { if (users[0].verificationCodeExpirationUtc > DateTime.UtcNow) { users[0].verificationCode = null; users[0].verificationCodeExpiration = null; users.Save(); UserDevices devices = new UserDevices(loginUser); UserDevice device = devices.AddNewUserDevice(); device.DateActivated = DateTime.UtcNow; device.IsActivated = true; device.DeviceID = Guid.NewGuid().ToString(); device.UserID = users[0].UserID; devices.Save(); EmailPosts.SendNewDevice(loginUser, users[0].UserID); HttpCookie deviceCookie = new HttpCookie("di", device.DeviceID); deviceCookie.Expires = DateTime.Now.AddYears(14); HttpContext.Current.Response.Cookies.Add(deviceCookie); result.Result = LoginResult.Success; string authenticateResult = AuthenticateUser(users[0].UserID, users[0].OrganizationID, false, false); } else { result.Error = "Verification Code has expired."; result.Result = LoginResult.Fail; } } else { result.Error = "Invalid Verification Code."; result.Result = LoginResult.Fail; } } else { result.Error = "User not found."; result.Result = LoginResult.Fail; } } catch (Exception ex) { result.Error = ex.Message; result.Result = LoginResult.Fail; } return(JsonConvert.SerializeObject(result)); }
public override bool Save() { User user; Users users = new Users(UserSession.LoginUser); Organization organization = Organizations.GetOrganization(UserSession.LoginUser, UserSession.LoginUser.OrganizationID); string email = textEmail.Text.Trim(); if (email.Length < 1 || email.IndexOf('@') < 0 || email.IndexOf('.') < 0 || !users.IsEmailValid(email, _userID, _organizationID)) { _manager.Alert("The email you have specified is invalid. Please choose another email."); return(false); } if (textFirstName.Text.Trim().Length < 1 || textLastName.Text.Trim().Length < 1) { _manager.Alert("The name you have specified is invalid. Please enter your name."); return(false); } if (cbChat.Checked && Organizations.GetChatCount(UserSession.LoginUser, UserSession.LoginUser.OrganizationID) >= organization.ChatSeats) { _manager.Alert("You have exceeded your chat licenses. Please purchase more seats to add additional chat users."); cbChat.Checked = false; return(false); } if (_userID < 0) { if (Organizations.GetUserCount(UserSession.LoginUser, UserSession.LoginUser.OrganizationID) >= organization.UserSeats) { _manager.Alert("You have exceeded your user licenses. Please send an email to [email protected] if you would like to add additional users your account."); return(false); } user = users.AddNewUser(); user.OrganizationID = _organizationID; if (cbActive.Checked) { user.ActivatedOn = DateTime.UtcNow; } user.LastLogin = DateTime.UtcNow; user.LastActivity = DateTime.UtcNow; user.IsPasswordExpired = true; user.ReceiveTicketNotifications = true; user.EnforceSingleSession = true; user.IsClassicView = true; } else { users.LoadByUserID(_userID); if (users.IsEmpty) { _manager.Alert("There was an error updating the user information"); return(false); } user = users[0]; if (user.IsActive && !cbActive.Checked) { user.DeactivatedOn = DateTime.UtcNow; Organizations orgs = new Organizations(TSAuthentication.GetLoginUser()); orgs.ResetDefaultSupportUser(TSAuthentication.GetLoginUser(), user.UserID); } if (true) { if (!user.IsActive && cbActive.Checked && Organizations.GetUserCount(UserSession.LoginUser, UserSession.LoginUser.OrganizationID) >= organization.UserSeats) { _manager.Alert("You have exceeded your user licenses. Please send an email to [email protected] if you would like to add additional users your account."); return(false); } } } user.Email = textEmail.Text.Trim(); user.FirstName = textFirstName.Text.Trim(); user.LastName = textLastName.Text.Trim(); user.MiddleName = textMiddleName.Text.Trim(); user.Title = textTitle.Text; user.IsPortalUser = true; user.TimeZoneID = cmbTimeZones.SelectedValue; user.CultureName = cmbDateFormat.SelectedValue; user.FontFamily = (FontFamily)Convert.ToInt32(cmbFontFamilies.SelectedValue); user.FontSize = (TeamSupport.Data.FontSize)Convert.ToInt32(cmbFontSizes.SelectedValue); user.ReceiveTicketNotifications = cbEmailNotify.Checked; user.SubscribeToNewTickets = cbSubscribe.Checked; user.SubscribeToNewActions = cbSubscribeAction.Checked; user.ReceiveAllGroupNotifications = cbReceiveGroup.Checked; user.DoNotAutoSubscribe = cbNoAutoSubscribe.Checked; user.RestrictUserFromEditingAnyActions = cbRestrictUserFromEditingAnyActions.Checked; user.AllowUserToEditAnyAction = cbAllowUserToEditAnyAction.Checked; user.UserCanPinAction = cbUserCanPinAction.Checked; user.TicketRights = (TicketRightType)int.Parse(cmbRights.SelectedValue); user.ShowWelcomePage = true; UserSession.LoginUser.TimeZoneInfo = null; if (UserSession.CurrentUser.IsSystemAdmin) { user.IsActive = cbActive.Checked; user.IsSystemAdmin = cbIsSystemAdmin.Checked; user.IsChatUser = cbChat.Checked; } string checkRequired = _fieldControls.CheckRequiredCustomFields(); if (checkRequired != "") { _manager.Alert(checkRequired); return(false); } user.Collection.Save(); if (user.IsActive) { user.EmailCountToMuroc(true); } _fieldControls.RefID = user.UserID; _fieldControls.SaveCustomFields(); if (_userID < 0) { string password = DataUtils.GenerateRandomPassword(); user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); user.IsPasswordExpired = true; user.PasswordCreatedUtc = DateTime.UtcNow; user.Collection.Save(); if (cbEmail.Checked) { EmailPosts.SendWelcomeTSUser(UserSession.LoginUser, user.UserID, password); } Organization orgTemplate = Organizations.GetTemplateOrganization(UserSession.LoginUser, organization.ProductType); if (orgTemplate != null) { UserSettings.WriteString(UserSession.LoginUser, user.UserID, "Dashboard", UserSettings.ReadString(UserSession.LoginUser, (int)orgTemplate.PrimaryUserID, "Dashboard")); } } TeamSupportSync.SyncUser(user.UserID, user.OrganizationID, user.FirstName, user.LastName, user.Email, user.Title); if (UserSession.CurrentUser.UserID == _userID) { UserSession.RefreshCurrentUserInfo(); UserSession.RefreshLoginUser(); } return(true); }
public override bool Save() { User user; Users users = new Users(UserSession.LoginUser);; int newOrgID = int.Parse(cmbCustomer.SelectedValue); string email = textEmail.Text.Trim(); if ((cbIsPortalUser.Checked) && (email.Length < 1 || email.IndexOf('@') < 0 || email.IndexOf('.') < 0)) { _manager.Alert("The email you have specified is invalid. Please choose another email."); return(false); } if (email != "" && !users.IsEmailValid(email, _userID, newOrgID)) { _manager.Alert("The email you have specified is already in use. Please choose another email."); return(false); } if (textFirstName.Text.Trim().Length < 1 || textLastName.Text.Trim().Length < 1) { _manager.Alert("The name you have specified is invalid. Please enter your name."); return(false); } if (_userID < 0) { user = users.AddNewUser(); user.OrganizationID = newOrgID; if (cbActive.Checked) { user.ActivatedOn = DateTime.UtcNow; } user.LastLogin = DateTime.UtcNow; user.LastActivity = DateTime.UtcNow.AddHours(-1); user.IsPasswordExpired = true; user.ReceiveTicketNotifications = true; } else { users.LoadByUserID(_userID); if (users.IsEmpty) { _manager.Alert("There was an error updating the user information"); return(false); } user = users[0]; if (user.IsActive && !cbActive.Checked) { user.DeactivatedOn = DateTime.UtcNow; } if (user.OrganizationID != newOrgID) { user.OrganizationID = newOrgID; Tickets tickets = new Tickets(UserSession.LoginUser); tickets.LoadByContact(user.UserID); foreach (Ticket ticket in tickets) { tickets.AddOrganization(newOrgID, ticket.TicketID); } } } user.Email = textEmail.Text; user.FirstName = textFirstName.Text; user.LastName = textLastName.Text; user.Title = textTitle.Text; user.MiddleName = textMiddleName.Text; user.BlockInboundEmail = cbBlockEmail.Checked; user.IsActive = cbActive.Checked; if (UserSession.CurrentUser.HasPortalRights && UserSession.CurrentUser.IsSystemAdmin) { user.IsPortalUser = cbIsPortalUser.Checked; } if (UserSession.CurrentUser.IsTSUser && UserSession.CurrentUser.IsSystemAdmin) { user.IsSystemAdmin = cbIsSystemAdmin.Checked; user.IsFinanceAdmin = cbIsFinanceAdmin.Checked; } user.Collection.Save(); _fieldControls.RefID = user.UserID; _fieldControls.SaveCustomFields(); if (_userID < 0) { string password = DataUtils.GenerateRandomPassword(); user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); user.IsPasswordExpired = true; user.Collection.Save(); if (UserSession.CurrentUser.IsTSUser && cbEmail.Checked) { EmailPosts.SendWelcomeTSUser(UserSession.LoginUser, user.UserID, password); } else if (cbEmail.Checked && cbIsPortalUser.Checked) { EmailPosts.SendWelcomePortalUser(UserSession.LoginUser, user.UserID, password); } } return(true); }
public static string UpdateContact(RestCommand command, int id) { User user = Users.GetUser(command.LoginUser, id); User oldUser = Users.GetUser(command.LoginUser, id); if (user == null) { throw new RestException(HttpStatusCode.BadRequest); } Organization organization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID); if (organization.ParentID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } bool allowOrganizationIdUpdate = true; user.ReadFromXml(command.Data, false, allowOrganizationIdUpdate); if (user.CryptedPassword != oldUser.CryptedPassword) { user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(user.CryptedPassword, "MD5"); } bool isChangingOrganizationId = oldUser.OrganizationID != user.OrganizationID; if (isChangingOrganizationId) { Organization newOrganization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID); if (newOrganization.ParentID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } //Let's follow the same reflexes as the UI (..\webapp\app_code\customerservice.cs SetContactCompany()) Tickets t = new Tickets(command.LoginUser); t.LoadByContact(id); foreach (Ticket tix in t) { tix.Collection.RemoveContact(id, tix.TicketID); } user.PortalAutoReg = false; user.Collection.Save(); foreach (Ticket tix in t) { tix.Collection.AddContact(id, tix.TicketID); } EmailPosts ep = new EmailPosts(command.LoginUser); ep.LoadByRecentUserID(id); ep.DeleteAll(); ep.Save(); } else { user.Collection.Save(); } user.UpdateCustomFieldsFromXml(command.Data); return(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", true)); }
private void RecoverTickets(int orgID, LoginUser loginUser) { Tickets badTickets = new Tickets(GetCorrupteLoginUser()); SqlCommand command = new SqlCommand(); command.CommandText = @" SELECT * FROM Tickets WHERE OrganizationID = @OrganizationID AND DateCreated > '2015-09-17 05:56:00' AND TicketSource != 'EMail' AND IgnoreMe = 0 "; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@OrganizationID", orgID); badTickets.Fill(command, ""); Organizations existingCompanies = new Organizations(loginUser); existingCompanies.LoadByParentID(orgID, false); foreach (Ticket badTicket in badTickets) { try { //Copy Ticket Ticket goodTicket = (new Tickets(loginUser)).AddNewTicket(); goodTicket.CopyRowData(badTicket); //Product if (badTicket.ProductID != null) { Product goodProduct = _goodProducts.FindByProductID((int)badTicket.ProductID); if (goodProduct == null) { Product badProduct = _badProducts.FindByProductID((int)badTicket.ProductID); goodProduct = _goodProducts.FindByName(badProduct.Name); if (goodProduct != null) { goodTicket.ProductID = goodProduct.ProductID; } else { goodTicket.ProductID = null; } } } //Version if (goodTicket.ProductID != null && badTicket.ReportedVersionID != null) { ProductVersion goodProductVersion = _goodProductVersions.FindByProductVersionID((int)badTicket.ReportedVersionID); if (goodProductVersion == null) { ProductVersion badProductVersion = _badProductVersions.FindByProductVersionID((int)badTicket.ReportedVersionID); goodProductVersion = _goodProductVersions.FindByVersionNumber(badProductVersion.VersionNumber, (int)goodTicket.ProductID); if (goodProductVersion != null) { goodTicket.ReportedVersionID = goodProductVersion.ProductVersionID; } else { goodTicket.ReportedVersionID = null; } } } //Solved Version if (goodTicket.ProductID != null && badTicket.SolvedVersionID != null) { ProductVersion goodProductVersion = _goodProductVersions.FindByProductVersionID((int)badTicket.SolvedVersionID); if (goodProductVersion == null) { ProductVersion badProductVersion = _badProductVersions.FindByProductVersionID((int)badTicket.SolvedVersionID); goodProductVersion = _goodProductVersions.FindByVersionNumber(badProductVersion.VersionNumber, (int)goodTicket.ProductID); if (goodProductVersion != null) { goodTicket.SolvedVersionID = goodProductVersion.ProductVersionID; } else { goodTicket.SolvedVersionID = null; } } } //Group if (badTicket.GroupID != null) { Group goodGroup = _goodGroups.FindByGroupID((int)badTicket.GroupID); if (goodGroup == null) { Group badGroup = _badGroups.FindByGroupID((int)badTicket.GroupID); goodGroup = _goodGroups.FindByName(badGroup.Name); if (goodGroup != null) { goodTicket.GroupID = goodGroup.GroupID; } else { goodTicket.GroupID = null; } } } //Assigned User if (badTicket.UserID != null) { User goodUser = _goodUsers.FindByUserID((int)badTicket.UserID); if (goodUser == null) { User badUser = _badUsers.FindByUserID((int)badTicket.UserID); goodUser = _goodUsers.FindByEmail(badUser.Email); if (goodUser != null) { goodTicket.UserID = goodUser.UserID; } else { goodTicket.UserID = null; } } } //Type TicketType goodTicketType = _goodTicketTypes.FindByTicketTypeID(badTicket.TicketTypeID); if (goodTicketType == null) { TicketType badTicketType = _badTicketTypes.FindByTicketTypeID(badTicket.TicketTypeID); goodTicketType = _goodTicketTypes.FindByName(badTicketType.Name); if (goodTicketType != null) { goodTicket.TicketTypeID = goodTicketType.TicketTypeID; } else { goodTicket.TicketTypeID = _goodTicketTypes[0].TicketTypeID; } } //Status TicketStatus goodTicketStatus = _goodTicketStatuses.FindByTicketStatusID(badTicket.TicketStatusID); if (goodTicketStatus == null) { TicketStatus badTicketStatus = _badTicketStatuses.FindByTicketStatusID(badTicket.TicketStatusID); goodTicketStatus = _goodTicketStatuses.FindByName(badTicketStatus.Name, goodTicket.TicketTypeID); if (goodTicketStatus != null) { goodTicket.TicketStatusID = goodTicketStatus.TicketStatusID; } else { goodTicketStatus = _goodTicketStatuses.FindTopOne(goodTicket.TicketTypeID); goodTicket.TicketStatusID = goodTicketStatus.TicketStatusID; } } //Severity TicketSeverity goodTicketSeverity = _goodTicketSeverities.FindByTicketSeverityID(badTicket.TicketSeverityID); if (goodTicketSeverity == null) { TicketSeverity badTicketSeverity = _badTicketSeverities.FindByTicketSeverityID(badTicket.TicketSeverityID); goodTicketSeverity = _goodTicketSeverities.FindByName(badTicketSeverity.Name); if (goodTicketSeverity != null) { goodTicket.TicketSeverityID = goodTicketSeverity.TicketSeverityID; } else { goodTicket.TicketSeverityID = _goodTicketSeverities[0].TicketSeverityID; } } //Knowledgebase Cat if (badTicket.KnowledgeBaseCategoryID != null) { KnowledgeBaseCategory goodKBCategory = _goodTicketKBCategories.FindByCategoryID((int)badTicket.KnowledgeBaseCategoryID); if (goodKBCategory == null) { KnowledgeBaseCategory badKBCategory = _badTicketKBCategories.FindByCategoryID((int)badTicket.KnowledgeBaseCategoryID); goodKBCategory = _goodTicketKBCategories.FindByName(badKBCategory.CategoryName); if (goodKBCategory != null) { goodTicket.KnowledgeBaseCategoryID = goodKBCategory.CategoryID; } else { goodTicket.KnowledgeBaseCategoryID = null; } } } //Parent Ticket (NOTE from MT: we decided as a team to null out this field to ensure no bad relationships can happen since we don't know the ticketID is a preserved field for every ticket. goodTicket.ParentID = null; //Closing User if (badTicket.CloserID != null) { User goodUser = _goodUsers.FindByUserID((int)badTicket.CloserID); if (goodUser == null) { User badUser = _badUsers.FindByUserID((int)badTicket.CloserID); goodUser = _goodUsers.FindByEmail(badUser.Email); if (goodUser != null) { goodTicket.CloserID = goodUser.UserID; } else { goodTicket.CloserID = null; } } } //Reset ticket dates goodTicket.DateCreated = badTicket.DateCreatedUtc; goodTicket.DateModified = badTicket.DateModifiedUtc; goodTicket.ParentID = null; goodTicket.ImportID = _importID; if (badTicket.CreatorID > 0) { User creator = _usersAndContacts.FindByUserID(badTicket.CreatorID); if (creator != null) { goodTicket.CreatorID = creator.UserID; } else { goodTicket.CreatorID = -5; } } else { goodTicket.CreatorID = badTicket.CreatorID; } if (badTicket.ModifierID > 0) { User modifier = _usersAndContacts.FindByUserID(badTicket.ModifierID); if (modifier != null) { goodTicket.ModifierID = modifier.UserID; } else { goodTicket.ModifierID = -5; } } else { goodTicket.ModifierID = badTicket.ModifierID; } goodTicket.TicketNumber = 0; goodTicket.Collection.Save(); EmailPosts.DeleteImportEmails(loginUser); Actions badActions = new Actions(GetCorrupteLoginUser()); badActions.LoadByTicketID(badTicket.TicketID); foreach (TeamSupport.Data.Action badAction in badActions) { TeamSupport.Data.Action goodAction = new Actions(loginUser).AddNewAction(); goodAction.CopyRowData(badAction); goodAction.DateCreated = badAction.DateCreatedUtc; goodAction.DateModified = badAction.DateCreatedUtc; goodAction.TicketID = goodTicket.TicketID; goodAction.ImportID = _importID; if (badAction.CreatorID > 0) { User creator = _usersAndContacts.FindByUserID(badAction.CreatorID); if (creator != null) { goodAction.CreatorID = creator.UserID; } else { goodAction.CreatorID = -5; } } else { goodAction.CreatorID = badAction.CreatorID; } if (badAction.ModifierID > 0) { User modifier = _usersAndContacts.FindByUserID(badAction.ModifierID); if (modifier != null) { goodAction.ModifierID = modifier.UserID; } else { goodAction.ModifierID = -5; } } else { goodAction.ModifierID = badAction.ModifierID; } goodAction.Collection.Save(); EmailPosts.DeleteImportEmails(loginUser); } Organizations orgs = new Organizations(GetCorrupteLoginUser()); orgs.LoadBTicketID(badTicket.TicketID); foreach (Organization org in orgs) { Organization goodCompany = existingCompanies.FindByName(org.Name); if (org.ParentID == orgID && goodCompany != null) { goodTicket.Collection.AddOrganization(goodCompany.OrganizationID, goodTicket.TicketID); EmailPosts.DeleteImportEmails(loginUser); } } RecoverTicketCustomValues(orgID, badTicket.TicketID, goodTicket.TicketID); EmailPosts.DeleteImportEmails(loginUser); } catch (Exception ex) { _exceptionOcurred = true; ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover"); } } }
//private void RecoverContacts(int orgID) //{ // // check corrupt db for different products,if so craete the new products, but do not use ID's // Users badContacts = new Users(GetCorrupteLoginUser()); // badContacts.LoadContacts(orgID, false); // Users goodContacts = new Users(GetReviewLoginUser()); // goodContacts.LoadContacts(orgID, false); // foreach (User badContact in badContacts) // { // User goodContact = goodContacts.FindBy(badCompany.Name); // if (goodCompany == null) // { // goodCompany = (new Organizations(GetReviewLoginUser())).AddNewOrganization(); // goodCompany.Name = badCompany.Name; // goodCompany.Description = badCompany.Description; // goodCompany.Website = badCompany.Website; // goodCompany.CompanyDomains = badCompany.CompanyDomains; // goodCompany.SAExpirationDate = badCompany.SAExpirationDate; // goodCompany.SlaLevelID = badCompany.SlaLevelID; // goodCompany.DateCreated = badCompany.DateCreated; // goodCompany.SupportHoursMonth = badCompany.SupportHoursMonth; // goodCompany.IsActive = badCompany.IsActive; // goodCompany.HasPortalAccess = badCompany.HasPortalAccess; // goodCompany.IsApiEnabled = badCompany.IsApiEnabled; // goodCompany.IsApiActive = badCompany.IsApiActive; // goodCompany.InActiveReason = badCompany.InActiveReason; // goodCompany.ExtraStorageUnits = badCompany.ExtraStorageUnits; // goodCompany.IsCustomerFree = badCompany.IsCustomerFree; // goodCompany.PortalSeats = badCompany.PortalSeats; // goodCompany.ProductType = badCompany.ProductType; // goodCompany.UserSeats = badCompany.UserSeats; // goodCompany.NeedsIndexing = badCompany.NeedsIndexing; // goodCompany.SystemEmailID = badCompany.SystemEmailID; // goodCompany.WebServiceID = badCompany.WebServiceID; // { // User defaultSupportUser = _usersAndContacts.FindByUserID((int)badCompany.DefaultSupportUserID); // if (defaultSupportUser != null) // { // goodCompany.DefaultSupportUserID = defaultSupportUser.UserID; // } // } // if (badCompany.CreatorID > 0) // { // User creator = _usersAndContacts.FindByUserID(badCompany.CreatorID); // if (creator != null) // { // goodCompany.CreatorID = creator.UserID; // } // else // { // goodCompany.CreatorID = -1; // } // } // else // { // goodCompany.CreatorID = badCompany.CreatorID; // } // goodCompany.ParentID = orgID; // goodCompany.ImportID = _importID; // goodCompany.Collection.Save(); // } // } //} /* * private void RecoverAssets(int orgID) * { * // check corrupt db for different products,if so craete the new products, but do not use ID's * Assets badAssets = new Assets(GetCorrupteLoginUser()); * badAssets.LoadByOrganizationIDCreatedAfterRestore(orgID); * * Assets goodAssets = new Assets(GetReviewLoginUser()); * goodAssets.LoadByOrganizationID(orgID); * * foreach (Asset badAsset in badAssets) * { * Asset goodAsset = goodAssets.FindByName(badAsset.Name); * try * { * if (goodAsset == null) * { * goodAsset = (new Assets(GetReviewLoginUser())).AddNewAsset(); * goodAsset.CopyRowData(badAsset); * goodAsset.DateCreated = badAsset.DateCreatedUtc; * goodAsset.DateModified = badAsset.DateModifiedUtc; * goodAsset.OrganizationID = orgID; * goodAsset.ImportID = _importID; * goodAsset.Collection.Save(); * if (goodAsset.Location == "1") * { * AssetAssignmentsView assetAssignments = new AssetAssignmentsView(GetCorrupteLoginUser()); * assetAssignments.LoadByAssetID(badAsset.AssetID); * foreach (AssetAssignmentsViewItem assetAssignment in assetAssignments) * { * AssetHistory assetHistory = new AssetHistory(GetReviewLoginUser()); * AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem(); * * DateTime now = DateTime.UtcNow; * * assetHistoryItem.AssetID = goodAsset.AssetID; * assetHistoryItem.OrganizationID = orgID; * assetHistoryItem.ActionTime = assetAssignment.ActionTime; * assetHistoryItem.ActionDescription = assetAssignment.ActionDescription; * assetHistoryItem.ShippedFrom = assetAssignment.ShippedFrom; * assetHistoryItem.ShippedFromRefType = assetAssignment.ShippedFromRefType; * assetHistoryItem.ShippedTo = assetAssignment.ShippedTo; * assetHistoryItem.TrackingNumber = assetAssignment.TrackingNumber; * assetHistoryItem.ShippingMethod = assetAssignment.ShippingMethod; * assetHistoryItem.ReferenceNum = assetAssignment.ReferenceNum; * assetHistoryItem.Comments = assetAssignment.Comments; * * assetHistoryItem.DateCreated = assetAssignment.DateCreatedUtc; * assetHistoryItem.Actor = assetAssignment.Actor; * assetHistoryItem.RefType = assetAssignment.RefType; * assetHistoryItem.DateModified = now; * * assetHistory.Save(); * * AssetAssignments goodAssetAssignments = new AssetAssignments(GetReviewLoginUser()); * AssetAssignment goodAssetAssignment = goodAssetAssignments.AddNewAssetAssignment(); * * goodAssetAssignment.HistoryID = assetHistoryItem.HistoryID; * * goodAssetAssignments.Save(); * } * } * } * * } * catch (Exception ex) * { * SaveOrgResults(orgID, "Failure: " + ex.Message); * ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover"); * } * } * } */ private void RecoverActionsFromOldTickets(int orgID, LoginUser loginUser) { Actions badActions = new Actions(GetCorrupteLoginUser()); SqlCommand command = new SqlCommand(); command.CommandText = @"SELECT a.*, t.TicketNumber, t.OrganizationID FROM Actions a LEFT JOIN Tickets t ON t.TicketID = a.TicketID WHERE (t.OrganizationID = @OrganizationID) AND a.DateCreated > '2015-09-17 05:56:00' AND t.DateCreated < '2015-09-17 05:56:00'"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@OrganizationID", orgID); badActions.Fill(command, ""); foreach (TeamSupport.Data.Action badAction in badActions) { try { TeamSupport.Data.Action goodAction = new Actions(loginUser).AddNewAction(); goodAction.CopyRowData(badAction); goodAction.DateCreated = badAction.DateCreatedUtc; goodAction.DateModified = badAction.DateModifiedUtc; goodAction.TicketID = badAction.TicketID; if (badAction.CreatorID > 0) { User creator = _usersAndContacts.FindByUserID(badAction.CreatorID); if (creator != null) { goodAction.CreatorID = creator.UserID; } else { goodAction.CreatorID = -5; } } else { goodAction.CreatorID = badAction.CreatorID; } if (badAction.ModifierID > 0) { User modifier = _usersAndContacts.FindByUserID(badAction.ModifierID); if (modifier != null) { goodAction.ModifierID = modifier.UserID; } else { goodAction.ModifierID = -5; } } else { goodAction.ModifierID = badAction.ModifierID; } goodAction.ImportID = _importID; goodAction.Collection.Save(); Ticket ticket = Tickets.GetTicket(loginUser, goodAction.TicketID); ticket.ImportID = _importID; ticket.Collection.Save(); EmailPosts.DeleteImportEmails(loginUser); } catch (Exception ex) { _exceptionOcurred = true; ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover"); } } }