/// <summary> /// Deprecated Method for adding a new object to the TicketTags EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToTicketTags(TicketTag ticketTag) { base.AddObject("TicketTags", ticketTag); }
/// <summary> /// Edits the ticket. /// </summary> /// <param name="ticket">The ticket being edited with updated values.</param> /// <param name="comment">The comment.</param> /// <returns></returns> public bool EditTicketDetails(Ticket ticket, string comment) { var changes = Repository.GetTicketChanges(ticket); var rnv = new NameValueCollection(); if (!CheckSecurityForTicketActivity(ticket, TicketActivity.EditTicketInfo)) { rnv.Add("noAuth", "User is not authorized to edit ticket details"); } //There are only certain fields we allow to be changed, check rules List<string> allowedFieldChanges = new List<string> { "Title", "Details", "Priority", "Type", "Category", "Owner", "TagList" }; foreach (var field in changes) { if (!allowedFieldChanges.Contains(field.Key)) { rnv.Add("ticketInfo", string.Format("Changes to field {0} are not allowed", field.Key)); } } //handle taglist changed by removing all existing tags and rebuilding them //NOTE: We could examine the tags and just make removals and insertions as needed, but the // actual performance suffers very little and is not worth the extra effort and complexity. if (changes.ContainsKey("TagList")) { Repository.ClearTags(ticket, false); string[] tagsArr = TagUtility.GetTagsFromString(ticket.TagList); foreach (string tag in tagsArr) { TicketTag tTag = new TicketTag(); tTag.TagName = tag; ticket.TicketTags.Add(tTag); } ticket.TagList = string.Join(",", tagsArr);//in case the tags array trimmed spaces and such } rnv.Add(ValidateTicketDetailFields(ticket));//check the field rules if (changes.Count < 1) { rnv.Add("ticketInfo", "No changes to ticket's details were found."); } if (rnv.Count > 0) { throw new RuleException(rnv); } var ticketComment = GetActivityComment(TicketActivity.EditTicketInfo, comment, ticket.AssignedTo, ticket.GetNotificationSubscribers()); StringBuilder sb = new StringBuilder(); foreach (var c in changes) { string v = null; PropertyInfo pi = ticket.GetType().GetProperty(c.Key); if (pi != null) { v = pi.GetValue(ticket, null) as string; } if (c.Key != "Details" && c.Key != "Title" && c.Key != "TagList" && c.Key != "Owner") { sb.Append(string.Format("- Changed {0} from \"{1}\" to \"{2}\"\n", c.Key.ConvertPascalCaseToFriendlyString(), c.Value, v)); } else if (c.Key == "Owner") { sb.Append(string.Format("- Changed {0} from \"{1}\" to \"{2}\"\n", c.Key.ConvertPascalCaseToFriendlyString(), Security.GetUserDisplayName(c.Value as string), Security.GetUserDisplayName(v))); } else //details, title, and tags are long strings so we don't include the full text of the old and new values { sb.Append(string.Format("- Changed {0}\n", c.Key.ConvertPascalCaseToFriendlyString())); } } if (ticketComment.Comment.Length > 0) { sb.Append("\n******\n"); sb.Append(ticketComment.Comment); } ticketComment.Comment = sb.ToString(); ticket.TicketComments.Add(ticketComment); ticket.LastUpdateBy = Security.CurrentUserName; ticket.LastUpdateDate = DateTime.Now; return Repository.UpdateTicket(ticket); }
/// <summary> /// Create a new TicketTag object. /// </summary> /// <param name="ticketTagId">Initial value of the TicketTagId property.</param> /// <param name="tagName">Initial value of the TagName property.</param> /// <param name="ticketId">Initial value of the TicketId property.</param> public static TicketTag CreateTicketTag(global::System.Int32 ticketTagId, global::System.String tagName, global::System.Int32 ticketId) { TicketTag ticketTag = new TicketTag(); ticketTag.TicketTagId = ticketTagId; ticketTag.TagName = tagName; ticketTag.TicketId = ticketId; return ticketTag; }
/// <summary> /// Creates the new ticket. /// </summary> /// <param name="newTicket">The new ticket.</param> /// <param name="filesToAttach">The files to attach.</param> /// <param name="creatorUserName">User name of the creator.</param> /// <param name="creatorDisplayName">Display name of the creator.</param> /// <param name="ownerDisplayName">Display name of the owner.</param> /// <returns></returns> public int? CreateNewTicket(Ticket newTicket) { var rnv = new NameValueCollection(); if (!CheckSecurityForTicketActivity(null, TicketActivity.Create))// don't need to check CreateOnBehalfOf separately { rnv.Add("noAuth", "User is not authorized to create a ticket"); } var now = DateTime.Now; newTicket.CreatedBy = Security.CurrentUserName; newTicket.CreatedDate = now; newTicket.CurrentStatus = "Active"; newTicket.CurrentStatusDate = now; newTicket.CurrentStatusSetBy = Security.CurrentUserName; newTicket.LastUpdateBy = Security.CurrentUserName; newTicket.LastUpdateDate = now; string[] tagsArr = TagUtility.GetTagsFromString(newTicket.TagList); foreach (string tag in tagsArr) { TicketTag tTag = new TicketTag(); tTag.TagName = tag; newTicket.TicketTags.Add(tTag); } rnv.Add(ValidateTicketDetailFields(newTicket));// enforce field rules if (rnv.Count > 0) { throw new RuleException(rnv); } //comment TicketComment openingComment = (!newTicket.Owner.Equals(Security.CurrentUserName, StringComparison.InvariantCultureIgnoreCase)) ? GetActivityComment(TicketActivity.CreateOnBehalfOf, TicketCommentFlag.CommentNotApplicable, null, newTicket.AssignedTo, newTicket.GetNotificationSubscribers(), Security.GetUserDisplayName(newTicket.Owner)) : GetActivityComment(TicketActivity.Create, TicketCommentFlag.CommentNotApplicable, null, newTicket.AssignedTo, newTicket.GetNotificationSubscribers()); newTicket.TicketComments.Add(openingComment); AddAttachmentsToNewTicket(newTicket, Security.CurrentUserName); int? newTicketId = null; if (Repository.CreateTicket(newTicket, true)) { newTicketId = newTicket.TicketId; } return newTicketId; }