Beispiel #1
0
        public static TimeSpan CalculatePausedTime(LoginUser loginUser, int organizationId, int triggerId, DateTime pausedOn, DateTime resumedOn, Logs logs = null)
        {
            SlaTrigger   slaTrigger   = SlaTriggers.GetSlaTrigger(loginUser, triggerId);
            Organization organization = Organizations.GetOrganization(loginUser, organizationId);

            SlaTickets.BusinessHours businessHours = new SlaTickets.BusinessHours()
            {
                DayStartUtc  = organization.BusinessDayStartUtc,
                DayEndUtc    = organization.BusinessDayEndUtc,
                BusinessDays = organization.BusinessDays
            };

            //Check if we should use SLA's business hours instead of Account's
            if (!slaTrigger.UseBusinessHours &&
                slaTrigger.DayStartUtc.HasValue &&
                slaTrigger.DayEndUtc.HasValue)
            {
                businessHours.DayStartUtc  = slaTrigger.DayStartUtc.Value;
                businessHours.DayEndUtc    = slaTrigger.DayEndUtc.Value;
                businessHours.BusinessDays = slaTrigger.Weekdays;
            }

            List <DateTime> daysToPause    = SlaTriggers.GetSpecificDaysToPause(slaTrigger.SlaTriggerID);
            bool            pauseOnHoliday = slaTrigger.PauseOnHoliday;
            CalendarEvents  holidays       = new CalendarEvents(loginUser);

            if (pauseOnHoliday)
            {
                holidays.LoadHolidays(organization.OrganizationID);
            }

            return(CalculatePausedTime(loginUser, organization, slaTrigger, pausedOn, resumedOn, businessHours, daysToPause, holidays, logs));
        }
        public static void DeleteByTicketSeverityID(LoginUser loginUser, int ticketSeverityID)
        {
            SlaTriggers triggers = new SlaTriggers(loginUser);

            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "DELETE FROM SlaTriggers WHERE (TicketSeverityID = @ticketSeverityID)";
                command.CommandType = CommandType.Text;
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@ticketSeverityID", ticketSeverityID);
                triggers.ExecuteNonQuery(command, "SlaTriggers");
            }
        }
Beispiel #3
0
        public static SlaTrigger GetSlaTrigger(LoginUser loginUser, int slaTriggerID)
        {
            SlaTriggers slaTriggers = new SlaTriggers(loginUser);

            slaTriggers.LoadBySlaTriggerID(slaTriggerID);
            if (slaTriggers.IsEmpty)
            {
                return(null);
            }
            else
            {
                return(slaTriggers[0]);
            }
        }
Beispiel #4
0
 public SlaTrigger(DataRow row, SlaTriggers slaTriggers) : base(row, slaTriggers)
 {
     _slaTriggers = slaTriggers;
 }
Beispiel #5
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);
        }
 partial void BeforeDBDelete(int ticketSeverityID)
 {
     SlaTriggers.DeleteByTicketSeverityID(LoginUser, ticketSeverityID);
 }