public static string SaveComments(int workItemID, dynamic comments) { Dictionary <string, string> result = new Dictionary <string, string>() { { "saved", "" }, { "ids", "" }, { "error", "" } }; bool saved = false; string errorMsg = string.Empty, ids = string.Empty; int commentId = 0, parentCommentId = 0; string commentText = string.Empty; foreach (dynamic comment in comments) { commentId = 0; parentCommentId = 0; //comment[0]=commentid, comment[1]=parentid, comment[2]=text try { commentText = comment[2].ToString(); if (string.IsNullOrWhiteSpace(comment[0].ToString()) || !int.TryParse(comment[0].ToString(), out commentId)) { int.TryParse(comment[1].ToString(), out parentCommentId); saved = WorkloadItem.WorkItem_Comment_Add(out commentId, out errorMsg, workItemID, parentCommentId, commentText); } else { saved = WorkloadItem.WorkItem_Comment_Update(out errorMsg, commentId, commentText); } if (saved) { ids += commentId.ToString() + ","; } } catch (Exception ex) { LogUtility.LogException(ex); errorMsg += ": " + ex.Message; } } ids = ids.TrimEnd(new char[] { ',' }); if (ids.Length > 0) { saved = true; Workload.SendWorkloadEmail("WorkItem", false, workItemID); } result["saved"] = saved.ToString(); result["ids"] = ids; result["error"] = errorMsg; return(JsonConvert.SerializeObject(result, Formatting.None)); }
public static string SaveChanges(string rows) { Dictionary <string, string> result = new Dictionary <string, string>() { { "saved", "0" } , { "failed", "0" } , { "savedIds", "" } , { "failedIds", "" } , { "error", "" } }; bool saved = false; int savedQty = 0, failedQty = 0; string ids = string.Empty, failedIds = string.Empty, errorMsg = string.Empty, tempMsg = string.Empty; try { DataTable dtjson = (DataTable)JsonConvert.DeserializeObject(rows, (typeof(DataTable))); if (dtjson == null || dtjson.Rows.Count == 0) { errorMsg = "Unable to save. No list of changes was provided."; } else { int id = 0; //save foreach (DataRow dr in dtjson.Rows) { id = 0; tempMsg = string.Empty; int.TryParse(dr["ITEMID"].ToString(), out id); WorkloadItem wi = WorkloadItem.WorkItem_GetObject(id); //update object with new values wi = parseDataRow(wi, dtjson.Clone(), dr); saved = WorkloadItem.WorkItem_QM_Update(wi, out tempMsg); if (saved) { ids += string.Format("{0}{1}", ids.Length > 0 ? "," : "", id.ToString()); savedQty += 1; Workload.SendWorkloadEmail("WorkItem", false, id); } else { failedQty += 1; } if (tempMsg.Length > 0) { errorMsg = string.Format("{0}{1}{2}", errorMsg, errorMsg.Length > 0 ? Environment.NewLine : "", tempMsg); } } } } catch (Exception ex) { LogUtility.LogException(ex); saved = false; errorMsg = ex.Message; } result["savedIds"] = ids; result["failedIds"] = failedIds; result["saved"] = savedQty.ToString(); result["failed"] = failedQty.ToString(); result["error"] = errorMsg; return(JsonConvert.SerializeObject(result, Formatting.None)); }
protected void btnSubmit_Click(Object sender, EventArgs e) { bool exists = false; int newAttachmentID = 0; int newModuleAttachmentID = 0; bool saved = false; string errorMsg = string.Empty; var dtfilesAttr = JsonConvert.DeserializeObject <DataTable>(inpHide.Value); if (this.Edit || (this.fileUpload1.HasFile)) { if (!this.Edit) //adding an attachment, not editing one { int i = 0; foreach (HttpPostedFile uploadedFile in fileUpload1.PostedFiles) { string fileName = ""; string fileExtension = ""; string strFileTypeID = ""; string strDescription = ""; int intAttachType = 0; Stream fStream = uploadedFile.InputStream; int fileLength = uploadedFile.ContentLength; byte[] fByte = new byte[fileLength]; string fileType = uploadedFile.ContentType; string[] splitFileName = fileName.Split('\\'); fileName = splitFileName[splitFileName.Length - 1]; fStream.Read(fByte, 0, fByte.Length); fStream.Close(); if (fileUpload1.PostedFiles.Count > 1) { fileName = dtfilesAttr.Rows[i]["name"].ToString(); strFileTypeID = dtfilesAttr.Rows[i]["type"].ToString(); int.TryParse(strFileTypeID, out intAttachType); strDescription = dtfilesAttr.Rows[i]["description"].ToString(); } else { fileName = uploadedFile.FileName; strFileTypeID = ddlAttachmentType.SelectedValue; int.TryParse(ddlAttachmentType.SelectedValue, out intAttachType); strDescription = txtDescription.Text; } splitFileName = fileName.Split('\\'); fileName = splitFileName[splitFileName.Length - 1]; splitFileName = fileName.Split('.'); fileExtension = splitFileName[splitFileName.Length - 1]; switch (Module.ToUpper()) { case "TASK": saved = WorkItem_Task.Attachment_Add(WorkItemTaskID: this.workItemTaskID , attachmentTypeID: intAttachType , fileName: fileName , title: strDescription , description: strDescription , fileData: fByte , extensionID: 0 , newAttachmentID: out newAttachmentID , newWorkItemAttachmentID: out newModuleAttachmentID , errorMsg: out errorMsg); break; case "WORKITEM": saved = WorkloadItem.Attachment_Add(workItemID: this.WorkItemID , attachmentTypeID: intAttachType , fileName: fileName , title: strDescription , description: strDescription , fileData: fByte , extensionID: 0 , newAttachmentID: out newAttachmentID , newWorkItemAttachmentID: out newModuleAttachmentID , errorMsg: out errorMsg); break; case "WORKREQUEST": saved = WorkRequest.Attachment_Add(workRequestID: this.WorkRequestID , attachmentTypeID: intAttachType , fileName: fileName , title: strDescription , description: strDescription , fileData: fByte , extensionID: 0 , newAttachmentID: out newAttachmentID , newWorkItemAttachmentID: out newModuleAttachmentID , errorMsg: out errorMsg); break; case "MEETING": saved = AOR.AORMeetingInstanceAttachment_Save(0, AORMeetingInstanceID, 0, intAttachType, fileName, strDescription, strDescription, fByte, out newAttachmentID); break; case "RQMTDESC": saved = RQMT.RQMTDescriptionAttachment_Save(0, RQMTDescriptionID, 0, intAttachType, fileName, strDescription, fByte, out newAttachmentID); break; case "MDIMAGE": Dictionary <string, string> result = new Dictionary <string, string> { { "saved", "false" }, { "exists", "false" }, { "newID", "0" }, { "error", "" } }; string[] allowedExtensions = new string[] { ".jpg", ".jpeg", ".png", ".gif" }; string extension = Path.GetExtension(fileName).ToLower(); if (!allowedExtensions.Contains(extension)) { continue; } result = MasterData.Image_Add(ImageName: strDescription, Description: strDescription, FileName: fileName, FileData: fByte); saved = result["saved"].ToUpper() == "TRUE"; errorMsg = result["error"]; break; case "NEWS": saved = WTSNews.NewsAttachment_Add(newsID: this.NewsID , attachmentTypeID: (int)AttachmentTypeEnum.News , fileName: fileName , title: strDescription , description: strDescription , fileData: fByte , extensionID: 0 , newAttachmentID: out newAttachmentID //, newWorkItemAttachmentID: out newModuleAttachmentID , errorMsg: out errorMsg); break; default: saved = WTSData.Attachment_Add(attachmentTypeID: intAttachType , fileName: fileName , title: strDescription , description: strDescription , fileData: fByte , extensionID: 0 , newID: out newAttachmentID , errorMsg: out errorMsg); break; } i += 1; } } else { string fileName = ""; fileName = fileUpload1.FileName; //Stream fStream = fileUpload1.PostedFile.InputStream; //int fileLength = fileUpload1.PostedFile.ContentLength; //byte[] fByte = new byte[fileLength]; string fileType = string.Empty; if (fileUpload1.PostedFile != null) { fileName = fileUpload1.PostedFile.FileName; fileType = fileUpload1.PostedFile.ContentType; } string[] splitFileName = fileName.Split('\\'); fileName = splitFileName[splitFileName.Length - 1]; splitFileName = fileName.Split('.'); string fileExtension = splitFileName[splitFileName.Length - 1]; //fStream.Read(fByte, 0, fByte.Length); //fStream.Close(); if (fileName == "") { fileName = this.OriginalFileName; } string attachmentType = ddlAttachmentType.SelectedValue; if (Module == "News") { attachmentType = ((int)AttachmentTypeEnum.News).ToString(); } saved = WTSData.Attachment_Update(attachmentID: this.AttachmentID , attachmentTypeID: int.Parse(attachmentType) , fileName: fileName , title: txtDescription.Text , description: txtDescription.Text //, fileData: fByte , exists: out exists , errorMsg: out errorMsg); } if (!saved || errorMsg.Length > 0) { lblError.Text = errorMsg; } else { if (!exists) { HasUploaded = 1; } else { AlreadyExists = 1; } if (Module.ToUpper() == "WORKITEM") { Workload.SendWorkloadEmail("WorkItem", false, this.WorkItemID); } } } }
public static string SaveTask(int taskID, int workItemID, int priorityID , string title, string description, int assignedToID, int primaryResourceID, int secondaryResourceID , int primaryBusResourceID, int secondaryBusResourceID , string plannedStartDate, string actualStartDate, int estimatedEffortID, int actualEffortID, string actualEndDate , int completionPercent, int statusID, int workItemTypeID, int businessRank, int sortOrder, string pageOption, string SRNumber, int assignedToRankID, int productVersionID, string dateNeeded, bool businessReview, string aors) { Dictionary <string, string> result = new Dictionary <string, string>() { { "saved", "" } , { "id", "0" } , { "error", "" } , { "pageOption", pageOption } }; bool saved = false, loaded = false, savedAOR = false; string errorMsg = string.Empty; try { HttpServerUtility server = HttpContext.Current.Server; description = server.UrlDecode(description); int submittedByID = 0; submittedByID = UserManagement.GetUserId_FromUsername(); WorkItem_Task task = new WorkItem_Task(taskID); if (taskID > 0) { loaded = task.Load(); } task.WorkItemID = workItemID; task.PriorityID = priorityID; task.Title = title; task.Description = description; task.AssignedResourceID = assignedToID; task.PrimaryResourceID = primaryResourceID; task.SecondaryResourceID = secondaryResourceID; task.PrimaryBusResourceID = primaryBusResourceID; task.SecondaryBusResourceID = secondaryBusResourceID; task.EstimatedStartDate = plannedStartDate; task.ActualStartDate = actualStartDate; task.EstimatedEffortID = estimatedEffortID; task.ActualEffortID = actualEffortID; task.ActualEndDate = actualEndDate; task.CompletionPercent = completionPercent; task.StatusID = statusID; task.WorkItemTypeID = workItemTypeID; task.BusinessRank = businessRank; task.Sort_Order = sortOrder; task.SRNumber = SRNumber; task.AssignedToRankID = assignedToRankID; task.ProductVersionID = productVersionID; task.NeedDate = dateNeeded; task.BusinessReview = businessReview; XmlDocument docAORs = (XmlDocument)JsonConvert.DeserializeXmlNode(aors, "aors"); if (taskID == 0) { task.SubmittedByID = submittedByID; saved = task.Add(newID: out taskID, errorMsg: out errorMsg); if (saved) { savedAOR = AOR.AORSubTask_Save(TaskID: taskID, AORs: docAORs, Add: 0, CascadeAOR: false); Workload.SendWorkloadEmail("WorkItemTask", true, taskID); } } else { if (loaded) { saved = task.Save(errorMsg: out errorMsg); } if (saved) { savedAOR = AOR.AORSubTask_Save(TaskID: taskID, AORs: docAORs, Add: 0, CascadeAOR: false); Workload.SendWorkloadEmail("WorkItemTask", false, taskID); } } } catch (Exception ex) { saved = false; errorMsg = ex.Message; LogUtility.LogException(ex); } result["saved"] = saved.ToString(); result["id"] = taskID.ToString(); result["error"] = errorMsg; return(JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.None)); }