/// <summary> /// Deletes the user. /// </summary> /// <param name="UserId">The user id.</param> public static void DeleteUser(int UserId) { using (DbTransaction tran = DbTransaction.Begin()) { foreach (IncidentBox box in IncidentBox.List()) { bool bWasModified = false; if (box.Document.GeneralBlock.ResponsiblePool.Contains(UserId)) { box.Document.GeneralBlock.ResponsiblePool.Remove(UserId); bWasModified = true; } if (box.Document.EMailRouterBlock.InformationRecipientList.Contains(UserId)) { box.Document.EMailRouterBlock.InformationRecipientList.Remove(UserId); bWasModified = true; } if (bWasModified) { IncidentBoxDocument.Save(box.Document); } } tran.Commit(); } }
/// <summary> /// Replases the user. /// </summary> /// <param name="OldUserId">The old user id.</param> /// <param name="NewUserId">The new user id.</param> public static void ReplaseUser(int OldUserId, int NewUserId) { using (DbTransaction tran = DbTransaction.Begin()) { foreach (IncidentBox box in IncidentBox.List()) { bool bWasModified = false; if (box.Document.GeneralBlock.AllowControl && box.Document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser && box.Document.GeneralBlock.Controller == OldUserId) { box.Document.GeneralBlock.Controller = NewUserId; bWasModified = true; } if (box.Document.GeneralBlock.Manager == OldUserId) { box.Document.GeneralBlock.Manager = NewUserId; bWasModified = true; } if (box.Document.GeneralBlock.ResponsibleAssignType == ResponsibleAssignType.CustomUser && box.Document.GeneralBlock.Responsible == OldUserId) { box.Document.GeneralBlock.Responsible = NewUserId; bWasModified = true; } if (box.Document.GeneralBlock.ResponsiblePool.Contains(OldUserId)) { box.Document.GeneralBlock.ResponsiblePool.Remove(OldUserId); bWasModified = true; } if (box.Document.EMailRouterBlock.InformationRecipientList.Contains(OldUserId)) { box.Document.EMailRouterBlock.InformationRecipientList.Remove(OldUserId); bWasModified = true; } if (bWasModified) { IncidentBoxDocument.Save(box.Document); } } tran.Commit(); } }
public static int Create(string Name, string IdentifierMask, bool IsDefault, int Index) { if (!CanModify()) { throw new AccessDeniedException(); } try { IncidentBoxRow row = new IncidentBoxRow(); row.Name = Name; row.IdentifierMask = IdentifierMask; row.IsDefault = IsDefault; row.Index = Index; row.Update(); // Create Default IncidentBoxDocument IncidentBoxDocument doc = IncidentBoxDocument.Load(row.PrimaryKeyId); doc.GeneralBlock.Manager = Security.CurrentUser.UserID; doc.GeneralBlock.Responsible = Security.CurrentUser.UserID; IncidentBoxDocument.Save(doc); return(row.PrimaryKeyId); } catch (System.Data.SqlClient.SqlException ex) { if (ex.Message.IndexOf("'IX_IncidentBox_1'") != -1) { throw new IncidentBoxDuplicateIdentifierMaskException(); } else if (ex.Message.IndexOf("'IX_IncidentBox'") != -1) { throw new IncidentBoxDuplicateNameException(); } else { throw; } } }
public static void Update(IncidentBox box, IncidentBoxDocument document) { if (!CanModify()) { throw new AccessDeniedException(); } using (Database.DbTransaction tran = Database.DbTransaction.Begin()) { IncidentBox.Update(box); IncidentBoxDocument.Save(document); // O.R.[2008-12-16]: Recalculate Current Responsible DBIncident.RecalculateCurrentResponsibleByIncidentBox(box.IncidentBoxId); tran.Commit(); } }