public static string GetTicketHistory(LoginUser loginUser, int ticketID, DateTime?minUtcDate)
        {
            ActionLogs logs = new ActionLogs(loginUser);

            if (minUtcDate == null)
            {
                logs.LoadByTicketID(ticketID);
            }
            else
            {
                logs.LoadByTicketID(ticketID, (DateTime)minUtcDate);
            }

            if (logs.IsEmpty)
            {
                return("");
            }

            StringBuilder builder = new StringBuilder();

            builder.Append(@"<div style=""background-color: #EDF0F5; color: #004394; margin-bottom:10px; padding-left:5px; border: solid 1px #9FB0CF; font-size: 18px; font-weight: bold;"" class=""ui-corner-all"">Recent History</div>");

            foreach (ActionLog log in logs)
            {
                builder.Append(string.Format("<div style=\" color: #004394; padding-left:10px; \"><strong>{0}</strong>: {1} - <span style=\"font-style: italic;\">{2}</span></div>", log.CreatorName, log.Description, log.DateCreated.ToString("g", loginUser.CultureInfo)));
            }

            return(builder.ToString());
        }
        public static void RemoveSubscription(LoginUser loginUser, int userID, ReferenceType refType, int refID)
        {
            Subscriptions subscriptions = new Subscriptions(loginUser);

            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "DELETE FROM Subscriptions WHERE (RefType = @RefType) AND (RefID = @RefID) AND (UserID = @UserID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@UserID", userID);
                command.Parameters.AddWithValue("@RefType", (int)refType);
                command.Parameters.AddWithValue("@RefID", refID);
                subscriptions.ExecuteNonQuery(command, "Subscriptions,Tickets,Users");
            }


            string description = "Unsubscribed '" + Users.GetUserFullName(loginUser, userID) + "' from ";

            if (refType == ReferenceType.Tickets)
            {
                Ticket ticket = (Ticket)Tickets.GetTicket(loginUser, refID);
                description = description + Tickets.GetTicketLink(ticket);
            }
            ActionLogs.AddActionLog(loginUser, ActionLogType.Delete, refType, refID, description);
            ActionLogs.AddActionLog(loginUser, ActionLogType.Delete, ReferenceType.Users, userID, description);
        }
        partial void AfterRowInsert(ProductVersion productVersion)
        {
            Product product     = (Product)Products.GetProduct(LoginUser, productVersion.ProductID);
            string  description = "Created new version '" + productVersion.VersionNumber + "' for product '" + product.Name + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.ProductVersions, productVersion.ProductVersionID, description);
        }
        partial void BeforeRowDelete(int productID)
        {
            Product product     = (Product)Products.GetProduct(LoginUser, productID);
            string  description = "Deleted product '" + product.Name + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Products, productID, description);
        }
        public void AddCustomer(int organizationID, int productID)
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = @"INSERT INTO 
          OrganizationProducts 
          (OrganizationID, ProductID, IsVisibleOnPortal, DateCreated, DateModified, CreatorID, ModifierID) 
          VALUES 
          (@OrganizationID, @ProductID, 1, @DateCreated, @DateModified, @CreatorID, @ModifierID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@OrganizationID", organizationID);
                command.Parameters.AddWithValue("@ProductID", productID);
                command.Parameters.AddWithValue("@DateCreated", DateTime.UtcNow);
                command.Parameters.AddWithValue("@DateModified", DateTime.UtcNow);
                command.Parameters.AddWithValue("@CreatorID", LoginUser.UserID);
                command.Parameters.AddWithValue("@ModifierID", LoginUser.UserID);
                ExecuteNonQuery(command, "OrganizationProducts");
            }

            string organizationName = ((Organization)Organizations.GetOrganization(LoginUser, organizationID)).Name;
            string productName      = ((Product)Products.GetProduct(LoginUser, productID)).Name;

            string description = "Added product '" + productName + "' to customer '" + organizationName + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Products, productID, description);
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Organizations, organizationID, description);
        }
        partial void BeforeRowDelete(int actionID)
        {
            Action action      = (Action)Actions.GetAction(LoginUser, actionID);
            string description = "Deleted action '" + action.Name + "' from " + Tickets.GetTicketLink(LoginUser, action.TicketID);

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Tickets, action.TicketID, description);
        }
        public static void AddSubscription(LoginUser loginUser, int userID, ReferenceType refType, int refID)
        {
            if (IsUserSubscribed(loginUser, userID, refType, refID))
            {
                return;
            }
            Subscriptions subscriptions = new Subscriptions(loginUser);

            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "INSERT INTO Subscriptions (RefType, RefID, UserID, DateCreated, DateModified, CreatorID, ModifierID) VALUES (@RefType, @RefID, @UserID, @DateCreated, @DateModified, @CreatorID, @ModifierID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@UserID", userID);
                command.Parameters.AddWithValue("@RefID", refID);
                command.Parameters.AddWithValue("@RefType", (int)refType);
                command.Parameters.AddWithValue("@DateCreated", DateTime.UtcNow);
                command.Parameters.AddWithValue("@DateModified", DateTime.UtcNow);
                command.Parameters.AddWithValue("@CreatorID", loginUser.UserID);
                command.Parameters.AddWithValue("@ModifierID", loginUser.UserID);
                subscriptions.ExecuteNonQuery(command, "Subscriptions,Tickets,Users");
            }

            string description = "Subscribed '" + Users.GetUserFullName(loginUser, userID) + "' to ";

            if (refType == ReferenceType.Tickets)
            {
                Ticket ticket = (Ticket)Tickets.GetTicket(loginUser, refID);
                description = description + Tickets.GetTicketLink(ticket);
            }

            ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, refType, refID, description);
            ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Users, userID, description);
        }
        partial void BeforeRowDelete(int productVersionID)
        {
            ProductVersion version     = (ProductVersion)ProductVersions.GetProductVersion(LoginUser, productVersionID);
            Product        product     = (Product)Products.GetProduct(LoginUser, version.ProductID);
            string         description = "Deleted version '" + version.VersionNumber + "' for product '" + product.Name + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.ProductVersions, productVersionID, description);
        }
        //public struct UserID
        //{
        //    public int _value;
        //    static public explicit operator UserID(int refID) { return new UserID() { _value = refID }; }
        //}
        //public static void AddActionLog(LoginUser loginUser, ActionLogType type, UserID refID, string description)
        //{
        //    AddActionLog(loginUser, type, ReferenceType.Users, refID._value, description);
        //}

        //public struct TicketID
        //{
        //    public int _value;
        //    static public explicit operator TicketID(int refID) { return new TicketID() { _value = refID }; }
        //}
        //public static void AddActionLog(LoginUser loginUser, ActionLogType type, TicketID refID, string description)
        //{
        //    TicketLog.AddLog(loginUser, type, refID._value, description);
        //}

        public static void AddActionLog(LoginUser loginUser, ActionLogType type, ReferenceType refType, int refID, string description)
        {
            ActionLogs actionLogs = new ActionLogs(loginUser);
            ActionLog  actionLog  = actionLogs.AddNewActionLog();

            actionLog.Description    = description;
            actionLog.OrganizationID = loginUser.OrganizationID < 0 ? null : (int?)loginUser.OrganizationID;
            actionLog.ActionLogType  = type;
            actionLog.RefID          = refID;
            actionLog.RefType        = refType;
            actionLogs.Save();
        }
        public static void AddInternalActionLog(LoginUser loginUser, string description)
        {
            ActionLogs actionLogs = new ActionLogs(loginUser);
            ActionLog  actionLog  = actionLogs.AddNewActionLog();

            actionLog.Description    = description;
            actionLog.OrganizationID = null;
            actionLog.ActionLogType  = ActionLogType.Insert;
            actionLog.RefID          = -1;
            actionLog.RefType        = ReferenceType.SystemSettings;
            actionLogs.Save();
        }
        partial void BeforeRowEdit(Action action)
        {
            var oldAction = (Action)Actions.GetActionByID(LoginUser, action.ActionID);

            action.Description = HtmlUtility.FixScreenRFrame((action.Row["Description"] == DBNull.Value) ? string.Empty : action.Description);
            string actionNumber = GetActionNumber(action.TicketID, action.ActionID);
            string description  = "Modified action #" + actionNumber + " on " + Tickets.GetTicketLink(LoginUser, action.TicketID) + (oldAction.IsVisibleOnPortal != action.IsVisibleOnPortal ? " - action changed is visible to = " + action.IsVisibleOnPortal : "");

            if (!this.isAdminClean)
            {
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Tickets, action.TicketID, description);
            }
        }
Exemple #12
0
        public static ActionLog GetActionLog(LoginUser loginUser, int actionLogID)
        {
            ActionLogs actionLogs = new ActionLogs(loginUser);

            actionLogs.LoadByActionLogID(actionLogID);
            if (actionLogs.IsEmpty)
            {
                return(null);
            }
            else
            {
                return(actionLogs[0]);
            }
        }
        partial void BeforeRowEdit(CustomValue newValue)
        {
            CustomValue oldValue = CustomValues.GetCustomValue(LoginUser, newValue.CustomValueID);

            newValue.OrganizationID = LoginUser.OrganizationID;
            if (oldValue.Value == newValue.Value)
            {
                return;
            }
            CustomField customField = CustomFields.GetCustomField(LoginUser, newValue.CustomFieldID);
            string      format      = "Changed {0} from '{1}' to '{2}'.";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, customField.RefType, newValue.RefID, string.Format(format, customField.Name, oldValue.Value, newValue.Value));
        }
        partial void AfterRowInsert(Action action)
        {
            string description = string.Format("Added {0} action ", action.IsVisibleOnPortal ? "public" : "private");

            if (_actionLogInstantMessage != null)
            {
                description = _actionLogInstantMessage;
            }
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tickets, action.TicketID, description + action.Name + " to " + Tickets.GetTicketLink(LoginUser, action.TicketID));
            if (_updateChildTickets)
            {
                AddChildActions(action);
            }
        }
        public void RemoveCustomer(int organizationID, int productID)
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "DELETE FROM OrganizationProducts WHERE (ProductID = @ProductID) AND (OrganizationID = @OrganizationID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@OrganizationID", organizationID);
                command.Parameters.AddWithValue("@ProductID", productID);
                ExecuteNonQuery(command, "OrganizationProducts");
            }
            Organization org         = (Organization)Organizations.GetOrganization(LoginUser, organizationID);
            Product      product     = (Product)Products.GetProduct(LoginUser, productID);
            string       description = "Removed '" + product.Name + "' from the customer " + org.Name;

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Products, productID, description);
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Organizations, organizationID, description);
        }
Exemple #16
0
        public void DeleteGroupUser(int groupID, int userID)
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "DELETE FROM GroupUsers WHERE (UserID = @UserID) AND (GroupID = @GroupID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@UserID", userID);
                command.Parameters.AddWithValue("@GroupID", groupID);
                ExecuteNonQuery(command, "GroupUsers");
            }
            User   user        = (User)Users.GetUser(LoginUser, userID);
            Group  group       = (Group)Groups.GetGroup(LoginUser, groupID);
            string description = "Removed '" + user.FirstName + " " + user.LastName + "' from group '" + group.Name + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Groups, groupID, description);
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, userID, description);
        }
        partial void BeforeRowEdit(Product product)
        {
            string description;

            Product oldProduct = (Product)Products.GetProduct(LoginUser, product.ProductID);

            if (oldProduct.Description != product.Description)
            {
                description = "Changed description for product '" + product.Description + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Products, product.ProductID, description);
            }

            if (oldProduct.Name != product.Name)
            {
                description = "Changed product name '" + oldProduct.Description + "' to '" + product.Name + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Products, product.ProductID, description);
            }
        }
        partial void BeforeRowEdit(ProductVersion productVersion)
        {
            Product        product          = (Product)Products.GetProduct(LoginUser, productVersion.ProductID);
            ProductVersion oldVersion       = (ProductVersion)GetProductVersion(LoginUser, productVersion.ProductVersionID);
            string         description      = "";
            string         oldVersionString = oldVersion.ReleaseDate == null ? "empty" : ((DateTime)oldVersion.ReleaseDate).ToString(GetDateFormatNormal())
            ;

            if (oldVersion.Description != productVersion.Description)
            {
                description = "Changed description for version '" + productVersion.VersionNumber + "' on product '" + product.Name + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.ProductVersions, productVersion.ProductVersionID, description);
            }

            if (oldVersion.IsReleased != productVersion.IsReleased)
            {
                description = "Changed release status for version '" + productVersion.VersionNumber + "' on product '" + product.Name + "' to " + productVersion.IsReleased.ToString();
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.ProductVersions, productVersion.ProductVersionID, description);
            }

            if (oldVersion.ReleaseDate != productVersion.ReleaseDate)
            {
                description = "Changed the release date for version '" + productVersion.VersionNumber + "' on product '" + product.Name + "' from " + oldVersionString + "' to '" + ((DateTime)productVersion.ReleaseDate).ToString(GetDateFormatNormal()) + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.ProductVersions, productVersion.ProductVersionID, description);
            }

            if (oldVersion.VersionNumber != productVersion.VersionNumber)
            {
                description = "Changed the version number for version '" + productVersion.VersionNumber + "' on product '" + product.Name + "' to '" + productVersion.VersionNumber + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.ProductVersions, productVersion.ProductVersionID, description);
            }

            if (oldVersion.ProductVersionStatusID != productVersion.ProductVersionStatusID)
            {
                string oldStatus = ((ProductVersionStatus)ProductVersionStatuses.GetProductVersionStatus(LoginUser, oldVersion.ProductVersionStatusID)).Name;
                string newStatus = ((ProductVersionStatus)ProductVersionStatuses.GetProductVersionStatus(LoginUser, productVersion.ProductVersionStatusID)).Name;
                description = "Changed the status for version '" + productVersion.VersionNumber + "' on product '" + product.Name + "' from " + oldStatus + "' to '" + newStatus + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.ProductVersions, productVersion.ProductVersionID, description);
            }
        }
Exemple #19
0
        public void AddGroupUser(int userID, int groupID)
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "INSERT INTO GroupUsers (GroupID, UserID, DateCreated, DateModified, CreatorID, ModifierID) VALUES (@GroupID, @UserID, @DateCreated, @DateModified, @CreatorID, @ModifierID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@GroupID", groupID);
                command.Parameters.AddWithValue("@UserID", userID);
                command.Parameters.AddWithValue("@DateCreated", DateTime.UtcNow);
                command.Parameters.AddWithValue("@DateModified", DateTime.UtcNow);
                command.Parameters.AddWithValue("@CreatorID", LoginUser.UserID);
                command.Parameters.AddWithValue("@ModifierID", LoginUser.UserID);
                ExecuteNonQuery(command, "GroupUsers");
            }

            User   user        = (User)Users.GetUser(LoginUser, userID);
            Group  group       = (Group)Groups.GetGroup(LoginUser, groupID);
            string description = "Added '" + user.FirstName + " " + user.LastName + "' to group '" + group.Name + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Groups, groupID, description);
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, userID, description);
        }
        public void RemoveCustomer(int organizationProductID)
        {
            OrganizationProducts organizationProducts = new OrganizationProducts(LoginUser);

            organizationProducts.LoadItemInfo(organizationProductID);
            if (organizationProducts.IsEmpty)
            {
                return;
            }
            OrganizationProduct organizationProduct = organizationProducts[0];

            /*using (SqlCommand command = new SqlCommand())
             * {
             * command.CommandText = "DELETE FROM OrganizationProducts WHERE (OrganizationProductID = @OrganizationProductID)";
             * command.CommandType = CommandType.Text;
             * command.Parameters.AddWithValue("@OrganizationProductID", organizationProductID);
             * ExecuteNonQuery(command, "OrganizationProducts");
             * }*/

            string description;

            if (organizationProduct.ProductVersionID != null)
            {
                description = "Removed product '" + (string)organizationProduct.Row["ProductName"] + "' version '" + (string)organizationProduct.Row["VersionNumber"] + "' from customer '" +
                              (string)organizationProduct.Row["OrganizationName"] + "'";
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.ProductVersions, (int)organizationProduct.ProductVersionID, description);
            }
            else
            {
                description = "Removed product '" + (string)organizationProduct.Row["ProductName"] + "' from customer '" +
                              (string)organizationProduct.Row["OrganizationName"] + "'";
            }
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Organizations, organizationProduct.OrganizationID, description);
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Products, organizationProduct.ProductID, description);

            organizationProducts.DeleteFromDB(organizationProductID);
        }
        partial void AfterRowInsert(Product product)
        {
            string description = "Created product '" + product.Name + "'";

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Products, product.ProductID, description);
        }
Exemple #22
0
 public ActionLog(DataRow row, ActionLogs actionLogs) : base(row, actionLogs)
 {
     _actionLogs = actionLogs;
 }
Exemple #23
0
        public SlaLevel Clone(string cloneName = null)
        {
            int       cloneSlaLevelId = 0;
            LoginUser loginUser       = Collection.LoginUser;
            SlaLevels slaLevels       = new SlaLevels(loginUser);
            SlaLevel  clone           = slaLevels.AddNewSlaLevel();

            clone.OrganizationID = OrganizationID;

            if (string.IsNullOrEmpty(cloneName))
            {
                clone.Name = Name + " (Clone)";
            }
            else
            {
                clone.Name = cloneName;
            }

            clone.Collection.Save();
            cloneSlaLevelId = clone.SlaLevelID;

            string actionLog = string.Format("{0} cloned SLA Level {1} into {2}.", loginUser.GetUserFullName(), this.Name, clone.Name);

            ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Sla, cloneSlaLevelId, actionLog);

            //Clone SLA's triggers
            SlaTriggers clonedSlaTriggers   = new SlaTriggers(loginUser);
            SlaTriggers originalSlaTriggers = new SlaTriggers(loginUser);

            try
            {
                originalSlaTriggers.LoadBySlaLevel(OrganizationID, SlaLevelID);

                foreach (SlaTrigger slaTrigger in originalSlaTriggers.OrderBy(o => o.SlaTriggerID).ToList())
                {
                    SlaTrigger clonedSlaTrigger = clonedSlaTriggers.AddNewSlaTrigger();
                    slaTrigger.ClonePropertiesTo(clonedSlaTrigger);
                    clonedSlaTrigger.SlaLevelID = cloneSlaLevelId;
                }

                clonedSlaTriggers.BulkSave();
            }
            catch (Exception ex)
            {
                actionLog = string.Format("Failed to clone sla {0} Triggers into {1}.", this.SlaLevelID, clone.SlaLevelID);
                ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Sla, cloneSlaLevelId, actionLog);
                ExceptionLogs.LogException(loginUser, ex, "Cloning Sla Triggers", "SlaLevels.Clone - Triggers");
            }

            //Clone SLA's Pause on specific days
            try
            {
                clonedSlaTriggers = new SlaTriggers(loginUser);
                clonedSlaTriggers.LoadBySlaLevel(OrganizationID, cloneSlaLevelId);

                foreach (SlaTrigger slaTrigger in originalSlaTriggers)
                {
                    SlaPausedDays clonedSlaPausedDays   = new SlaPausedDays(loginUser);
                    SlaPausedDays originalSlaPausedDays = new SlaPausedDays(loginUser);
                    originalSlaPausedDays.LoadByTriggerID(slaTrigger.SlaTriggerID);
                    int newTriggerId = clonedSlaTriggers.Where(p => p.TicketTypeID == slaTrigger.TicketTypeID && p.TicketSeverityID == slaTrigger.TicketSeverityID && p.SlaLevelID == cloneSlaLevelId).First().SlaTriggerID;

                    foreach (SlaPausedDay slaPausedDay in originalSlaPausedDays.OrderBy(o => o.DateToPause).ToList())
                    {
                        SlaPausedDay clonedSlaPausedDay = clonedSlaPausedDays.AddNewSlaPausedDay();
                        clonedSlaPausedDay.SlaTriggerId = newTriggerId;
                        clonedSlaPausedDay.DateToPause  = slaPausedDay.DateToPauseUtc;
                    }

                    clonedSlaPausedDays.BulkSave();
                }
            }
            catch (Exception ex)
            {
                actionLog = string.Format("Failed to clone sla {0} DaysToPause into {1}.", this.SlaLevelID, clone.SlaLevelID);
                ActionLogs.AddActionLog(loginUser, ActionLogType.Insert, ReferenceType.Sla, cloneSlaLevelId, actionLog);
                ExceptionLogs.LogException(loginUser, ex, "Cloning Sla Pause On Days", "SlaLevels.Clone - Pause On Days");
            }

            return(clone);
        }