public bool Save(TicketComment eventComment) { var details = Request.Form["details"]; Dictionary<string, KeyValuePair<string, string>> fieldEventTextList = new Dictionary<string, KeyValuePair<string, string>>();//key is simple event test, value is full event text; if (TicketTitleEdit.Text != TicketToDisplay.Title) { fieldEventTextList.Add("changed ticket's title", GetFieldEventValues(TicketToDisplay.Title, TicketTitleEdit.Text)); TicketToDisplay.Title = TicketTitleEdit.Text; } if (details != TicketToDisplay.Details) { fieldEventTextList.Add("changed ticket's details", GetFieldEventValues(string.Empty,string.Empty)); TicketToDisplay.IsHtml = false; TicketToDisplay.Details = details; } if (CategoryEdit.Enabled && CategoryEdit.SelectedValue != TicketToDisplay.Category) { fieldEventTextList.Add("changed ticket's category", GetFieldEventValues(TicketToDisplay.Category, CategoryEdit.SelectedValue)); TicketToDisplay.Category = CategoryEdit.SelectedValue; } if (PriorityEdit.Enabled && PriorityEdit.SelectedValue != TicketToDisplay.Priority && !string.IsNullOrEmpty(PriorityEdit.SelectedValue)) { fieldEventTextList.Add("changed ticket's priority", GetFieldEventValues(TicketToDisplay.Priority, PriorityEdit.SelectedValue)); TicketToDisplay.Priority = PriorityEdit.SelectedValue; } if (OwnerEdit.Enabled && OwnerEdit.SelectedValue != TicketToDisplay.Owner) { fieldEventTextList.Add("changed ticket's owner", GetFieldEventValues(TicketToDisplay.Owner, OwnerEdit.SelectedValue)); TicketToDisplay.Owner = OwnerEdit.SelectedValue; } if (AffectsCustomerEdit.Checked != TicketToDisplay.AffectsCustomer) { KeyValuePair<string,string> e = GetFieldEventValues(((TicketToDisplay.AffectsCustomer) ? "Yes" : "No"), ((AffectsCustomerEdit.Checked) ? "Yes" : "No")); fieldEventTextList.Add("changed ticket's affects customer flag", e); TicketToDisplay.AffectsCustomer = AffectsCustomerEdit.Checked; } string[] tags = TagManager.GetTagsFromString(TagPickerEdit.TagList); string newTagList = string.Join(",", tags); if (newTagList != TicketToDisplay.TagList) { fieldEventTextList.Add("changed ticket's tags", GetFieldEventValues(TicketToDisplay.TagList, newTagList)); TicketToDisplay.TicketTags.Clear(); foreach (string tag in tags) { TicketTag tTag = new TicketTag(); tTag.TagName = tag; TicketToDisplay.TicketTags.Add(tTag); } TicketToDisplay.TagList = newTagList; } if (fieldEventTextList.Count > 0) { if (fieldEventTextList.Count > 1) { eventComment.CommentEvent = "has edited multiple fields"; } else { foreach (var v in fieldEventTextList)//lazy, using foreach even though only one element... just a more convienient way to get at the content { if (v.Key == "changed ticket's details") { eventComment.CommentEvent = v.Key; } else { eventComment.CommentEvent = string.Format("{0} from {1} to {2}", v.Key, v.Value.Key, v.Value.Value); } } } if (string.IsNullOrEmpty(eventComment.Comment)) { eventComment.CommentEvent = eventComment.CommentEvent + " without comment"; } StringBuilder sb = new StringBuilder(); foreach (var v in fieldEventTextList) { sb.Append("<div class='MultiFieldEditContainer'>"); sb.Append("<div class='MiltiFieldEditFieldName'>"); string fromtoString = GetFieldEventValuesHtml(v.Value.Key, v.Value.Value); sb.Append(v.Key.Substring(0, 1).ToUpper() + v.Key.Substring(1)); sb.Append("</div>"); if (v.Key != "changed ticket's details") { sb.Append(fromtoString); } sb.Append("</div>"); } if (!string.IsNullOrEmpty(eventComment.Comment)) { sb.Append("\n\n------------\n\n"); sb.Append(eventComment.Comment); } eventComment.Comment = sb.ToString(); EditComplete(eventComment); return true; } else { return false; } }
partial void DeleteTicketTag(TicketTag instance);
public Ticket GetNewTicket() { string details = Page.Request.Form["details"]; Ticket ticket = null; if (Page.IsValid) { if (!string.IsNullOrEmpty(details)) { DateTime now = DateTime.Now; string user = Page.User.Identity.GetFormattedUserName(); ticket = new Ticket(); ticket.Type = TypeDropDownList.SelectedValue; ticket.Category = CategoryDropDownList.SelectedValue; ticket.Title = TitleTextBox.Text; ticket.IsHtml = false; ticket.Details = details; if (!string.IsNullOrEmpty(PriorityDropDownList.SelectedValue)) { ticket.Priority = PriorityDropDownList.SelectedValue; } string[] tags = TagManager.GetTagsFromString(TagPickerControl.TagList); ticket.TagList = string.Join(",", tags); ticket.AffectsCustomer = AffectsCustomerCheckBox.Checked; ticket.PublishedToKb = false; ticket.CreatedBy = user; ticket.CreatedDate = now; if (CreateOnBehalfTextBox.Checked) { ticket.Owner = OwnerDropDownList.SelectedValue; } else { ticket.Owner = user; } ticket.CurrentStatus = "Active"; ticket.CurrentStatusSetBy = user; ticket.CurrentStatusDate = now; TicketComment openingComment = new TicketComment(); if (CreateOnBehalfTextBox.Checked) { openingComment.CommentEvent = string.Format("created the ticket on behalf of {0}", SecurityManager.GetUserDisplayName(ticket.Owner)); } else { openingComment.CommentEvent = string.Format("created the ticket"); } openingComment.CommentedBy = user; openingComment.CommentedDate = now; HttpFileCollection uploadedFiles = Request.Files; for (int i = 0; i < uploadedFiles.Count; i++) { HttpPostedFile userPostedFile = uploadedFiles[i]; if (userPostedFile.ContentLength > 0) { TicketAttachment attachment = new TicketAttachment(); string fName = Path.GetFileName(userPostedFile.FileName);//FileUploader.FileName; attachment.FileName = fName; var description = Page.Request.Form[fName]; if (!string.IsNullOrEmpty(description)) { if (description.Length > 500) { attachment.FileDescription = description.Substring(0, 500); } else { attachment.FileDescription = description; } } attachment.FileSize = userPostedFile.ContentLength;//FileUploader.PostedFile.ContentLength; string mtype = userPostedFile.ContentType; attachment.FileType = (string.IsNullOrEmpty(mtype) ? "application/octet-stream" : mtype); byte[] fileContent = new byte[userPostedFile.ContentLength]; userPostedFile.InputStream.Read(fileContent, 0, userPostedFile.ContentLength);//FileUploader.FileBytes; attachment.FileContents = fileContent; ticket.TicketAttachments.Add(attachment); } } ticket.TicketComments.Add(openingComment); foreach (string tag in tags) { TicketTag tTag = new TicketTag(); tTag.TagName = tag; ticket.TicketTags.Add(tTag); } } else { lblDetailsRequired.Visible = true; } } return ticket; }
partial void UpdateTicketTag(TicketTag instance);
partial void InsertTicketTag(TicketTag instance);
private void detach_TicketTags(TicketTag entity) { this.SendPropertyChanging(); entity.Ticket = null; }
private void attach_TicketTags(TicketTag entity) { this.SendPropertyChanging(); entity.Ticket = this; }
public bool Save(TicketComment eventComment) { var details = Request.Form["details"]; Dictionary<string, KeyValuePair<string, string>> fieldEventTextList = new Dictionary<string, KeyValuePair<string, string>>();//key is simple event test, value is full event text; if (TicketTitleEdit.Text != TicketToDisplay.Title) { fieldEventTextList.Add("изменить название", GetFieldEventValues(TicketToDisplay.Title, TicketTitleEdit.Text)); TicketToDisplay.Title = TicketTitleEdit.Text; } if (details != TicketToDisplay.Details) { fieldEventTextList.Add("изменить описание", GetFieldEventValues(string.Empty,string.Empty)); TicketToDisplay.IsHtml = false; TicketToDisplay.Details = details; } if (CategoryEdit.Enabled && CategoryEdit.SelectedValue != TicketToDisplay.Category) { fieldEventTextList.Add("изменить присвоенную категорию", GetFieldEventValues(TicketToDisplay.Category, CategoryEdit.SelectedValue)); TicketToDisplay.Category = CategoryEdit.SelectedValue; } if (PriorityEdit.Enabled && PriorityEdit.SelectedValue != TicketToDisplay.Priority && !string.IsNullOrEmpty(PriorityEdit.SelectedValue)) { fieldEventTextList.Add("сменить приоритет", GetFieldEventValues(TicketToDisplay.Priority, PriorityEdit.SelectedValue)); TicketToDisplay.Priority = PriorityEdit.SelectedValue; } if (OwnerEdit.Enabled && OwnerEdit.SelectedValue != TicketToDisplay.Owner) { fieldEventTextList.Add("назначить другого владельца", GetFieldEventValues(TicketToDisplay.Owner, OwnerEdit.SelectedValue)); TicketToDisplay.Owner = OwnerEdit.SelectedValue; } if (AffectsCustomerEdit.Checked != TicketToDisplay.AffectsCustomer) { KeyValuePair<string,string> e = GetFieldEventValues(((TicketToDisplay.AffectsCustomer) ? "Да" : "Нет"), ((AffectsCustomerEdit.Checked) ? "Да" : "Нет")); fieldEventTextList.Add("снять флажок влияния на администратора", e); TicketToDisplay.AffectsCustomer = AffectsCustomerEdit.Checked; } string[] tags = TagManager.GetTagsFromString(TagPickerEdit.TagList); string newTagList = string.Join(",", tags); if (newTagList != TicketToDisplay.TagList) { fieldEventTextList.Add("редактировать тэги", GetFieldEventValues(TicketToDisplay.TagList, newTagList)); TicketToDisplay.TicketTags.Clear(); foreach (string tag in tags) { TicketTag tTag = new TicketTag(); tTag.TagName = tag; TicketToDisplay.TicketTags.Add(tTag); } TicketToDisplay.TagList = newTagList; } if (fieldEventTextList.Count > 0) { if (fieldEventTextList.Count > 1) { eventComment.CommentEvent = "было отредактировано несколько полей,"; } else { foreach (var v in fieldEventTextList)//lazy, using foreach even though only one element... just a more convienient way to get at the content { if (v.Key == "изменить описание") { eventComment.CommentEvent = v.Key; } else { eventComment.CommentEvent = string.Format("{0} из {1} в {2}", v.Key, v.Value.Key, v.Value.Value); } } } if (string.IsNullOrEmpty(eventComment.Comment)) { eventComment.CommentEvent = eventComment.CommentEvent + " без комментариев"; } StringBuilder sb = new StringBuilder(); foreach (var v in fieldEventTextList) { sb.Append("<div class='MultiFieldEditContainer'>"); sb.Append("<div class='MiltiFieldEditFieldName'>"); string fromtoString = GetFieldEventValuesHtml(v.Value.Key, v.Value.Value); sb.Append(v.Key.Substring(0, 1).ToUpper() + v.Key.Substring(1)); sb.Append("</div>"); if (v.Key != "изменить выбранное описание") { sb.Append(fromtoString); } sb.Append("</div>"); } if (!string.IsNullOrEmpty(eventComment.Comment)) { sb.Append("\n\n------------\n\n"); sb.Append(eventComment.Comment); } eventComment.Comment = sb.ToString(); EditComplete(eventComment); return true; } else { return false; } }