public IHttpActionResult GetApiJsonCommentTr(int id, int uid, Boolean isBackend = false) { var user = _userBusinessService.GetDetail(uid); List <TicketDiscussion> ticketDiscussions = _ticketDiscussionBusinessService.GetListByTicket(id); List <CustomTicketDiscussion> customTicketDiscussions = new List <CustomTicketDiscussion>(); List <TicketNote> ticketNotes = _ticketNoteBusinessService.GetListByTicket(id); ApiJsonStatus apiJsonStatusM = Factory.Create <ApiJsonStatus>("ApiJsonStatus", ClassType.clsTypeDataModel); List <ApiJsonCommentTR> apiJsonCommentTrml = new List <ApiJsonCommentTR>(); if (ticketDiscussions == null && ticketNotes == null) { return(NotFound()); } if (ticketDiscussions != null) { foreach (TicketDiscussion originCommentObject in ticketDiscussions) { CustomTicketDiscussion customCommentObject = new CustomTicketDiscussion() { TicketDiscussionId = originCommentObject.TicketDiscussionId, TicketId = originCommentObject.TicketId, UserId = originCommentObject.UserId, Description = originCommentObject.Description, CreatedAt = originCommentObject.CreatedAt, TicketNoteId = originCommentObject.TicketNoteId, Status = originCommentObject.Status, IsInserted = false }; customTicketDiscussions.Add(customCommentObject); } } Ticket ticket = _ticketBs.GetDetail(id); if (ticketNotes.Count > 0) { foreach (var ticketNote in ticketNotes) { List <ApiJsonCommentTR> noteChild = new List <ApiJsonCommentTR>(); if (ticketDiscussions != null) { foreach (CustomTicketDiscussion comment in customTicketDiscussions) { ApiJsonCommentDateTR apiJsonCommentDateTr1 = new ApiJsonCommentDateTR() { day = comment.CreatedAt?.ToString("dd MMM yyyy"), time = comment.CreatedAt?.ToString("hh:mm tt") }; ApiJsonCommentSenderTR apiJsonCommentSenderTr1 = new ApiJsonCommentSenderTR() { name = _userBusinessService.GetDetail(comment.UserId).Name, is_verified = true }; if (isBackend == false) { if (ticket.Responder == comment.UserId) { apiJsonCommentSenderTr1.type = "Responder"; } else { apiJsonCommentSenderTr1.type = "Participant"; if (ticket.Submiter == comment.UserId) { apiJsonCommentSenderTr1.type = "Submitter"; } } } else { apiJsonCommentSenderTr1.type = ticket.Submiter == comment.UserId ? "Submitter" : "Responder"; } var attachments1 = _discussionAttachmentBusinessService.GetByDiscussionId(comment.TicketDiscussionId); List <ApiJsonCommentImageTR> listAttachment1 = new List <ApiJsonCommentImageTR>(); string attachmentsPath1 = "/Upload/Discussion/"; if (attachments1 != null) { foreach (var attachment in attachments1) { listAttachment1.Add(new ApiJsonCommentImageTR { src = WebConfigure.GetDomain() + attachmentsPath1 + attachment.Name, nama = attachment.Name }); } } ApiJsonCommentTR apiJsonCommentTrm1 = new ApiJsonCommentTR { id = comment.TicketDiscussionId, date = apiJsonCommentDateTr1, sender = apiJsonCommentSenderTr1, text = comment.Description, image = listAttachment1, type = comment.UserId == user.UserId ? "sent" : "received" }; if (comment.TicketNoteId.Equals(ticketNote.TicketNoteId)) { noteChild.Add(apiJsonCommentTrm1); } else { if (comment.TicketNoteId.Equals(0) && comment.IsInserted.Equals(false)) { apiJsonCommentTrm1.isRemovable = (ticket.Responder == uid); apiJsonCommentTrml.Add(apiJsonCommentTrm1); comment.IsInserted = true; } } } } ApiJsonCommentDateTR apiJsonCommentDateTr = new ApiJsonCommentDateTR() { day = ticketNote.CreatedAt?.ToString("dd MMM yyyy"), time = ticketNote.CreatedAt?.ToString("hh:mm tt") }; ApiJsonCommentSenderTR apiJsonCommentSenderTr = new ApiJsonCommentSenderTR() { name = _userBusinessService.GetDetail(ticketNote.UserId).Name, is_verified = true }; if (isBackend == false) { if (ticket.TicketCategoryId != 9) { if (ticket.Responder == ticketNote.UserId) { apiJsonCommentSenderTr.type = "Responder"; } else { apiJsonCommentSenderTr.type = "Participant"; if (ticket.Submiter == ticketNote.UserId) { apiJsonCommentSenderTr.type = "Submitter"; } } } else if (ticket.TicketCategoryId == 9) { if (ticket.Submiter == ticketNote.UserId) { apiJsonCommentSenderTr.type = "Submitter"; } else { apiJsonCommentSenderTr.type = "Responder"; } } } else if (isBackend) { apiJsonCommentSenderTr.type = ticket.Submiter == ticketNote.UserId ? "Submitter" : "Responder"; } var attachments = _noteAttachmentBusinessService.GetByNoteId(ticketNote.TicketNoteId); List <ApiJsonCommentImageTR> listAttachment = new List <ApiJsonCommentImageTR>(); string attachmentsPath = "/Upload/Note/"; if (attachments != null) { foreach (var attachment in attachments) { listAttachment.Add(new ApiJsonCommentImageTR { src = WebConfigure.GetDomain() + attachmentsPath + attachment.Name, nama = attachment.Name }); } } ApiJsonCommentTR apiJsonCommentTrm = new ApiJsonCommentTR() { type = "notes", date = apiJsonCommentDateTr, sender = apiJsonCommentSenderTr, text = ticketNote.Description, image = listAttachment, children = noteChild }; apiJsonCommentTrml.Add(apiJsonCommentTrm); } } else { if (ticketDiscussions != null) { foreach (TicketDiscussion ticketDiscussion in ticketDiscussions) { ApiJsonCommentDateTR apiJsonCommentDateTr1 = new ApiJsonCommentDateTR() { day = ticketDiscussion.CreatedAt?.ToString("dd MMM yyyy"), time = ticketDiscussion.CreatedAt?.ToString("hh:mm tt") }; ApiJsonCommentSenderTR apiJsonCommentSenderTr1 = new ApiJsonCommentSenderTR() { name = _userBusinessService.GetDetail(ticketDiscussion.UserId).Name, is_verified = true }; if (isBackend == false) { if (ticket.Responder == ticketDiscussion.UserId) { apiJsonCommentSenderTr1.type = "Responder"; } else { apiJsonCommentSenderTr1.type = "Participant"; if (ticket.Submiter == ticketDiscussion.UserId) { apiJsonCommentSenderTr1.type = "Submitter"; } } } else if (isBackend) { apiJsonCommentSenderTr1.type = ticket.Submiter == ticketDiscussion.UserId ? "Submitter" : "Responder"; } var attachments1 = _discussionAttachmentBusinessService.GetByDiscussionId(ticketDiscussion.TicketDiscussionId); List <ApiJsonCommentImageTR> listAttachment1 = new List <ApiJsonCommentImageTR>(); string attachmentsPath1 = "/Upload/Discussion/"; if (attachments1 != null) { foreach (var attachment in attachments1) { listAttachment1.Add(new ApiJsonCommentImageTR { src = WebConfigure.GetDomain() + attachmentsPath1 + attachment.Name, nama = attachment.Name }); } } ApiJsonCommentTR apiJsonCommentTrm1 = new ApiJsonCommentTR { id = ticketDiscussion.TicketDiscussionId, date = apiJsonCommentDateTr1, sender = apiJsonCommentSenderTr1, text = ticketDiscussion.Description, image = listAttachment1, isRemovable = (ticket.Responder == uid), type = ticketDiscussion.UserId == user.UserId ? "sent" : "received" }; apiJsonCommentTrml.Add(apiJsonCommentTrm1); } } } apiJsonStatusM.code = 200; apiJsonStatusM.message = "ok"; return(Ok(new { status = apiJsonStatusM, data = apiJsonCommentTrml })); }
public IHttpActionResult PostApiJsonCommentTr(int id, int uid, TicketDiscussionRemoveChat removeChat) { //int removeChat = Convert.ToInt32(formCollection["removeChat"]); if (_ticketDiscussionBusinessService.DeleteDiscussion(_ticketDiscussionBusinessService.GetDetail(removeChat.removeChat)).Status == 0) { List <TicketDiscussion> ticketDiscussions = _ticketDiscussionBusinessService.GetListByTicket(id); List <TicketNote> ticketNotes = _ticketNoteBusinessService.GetListByTicket(id); ApiJsonStatus apiJsonStatusM = Factory.Create <ApiJsonStatus>("ApiJsonStatus", ClassType.clsTypeDataModel); List <ApiJsonCommentTR> apiJsonCommentTrml = new List <ApiJsonCommentTR>(); if (ticketDiscussions == null && ticketNotes == null) { return(NotFound()); } Ticket ticket = _ticketBs.GetDetail(id); List <TicketParcipant> ticketParticipants = _ticketParcipantBusinessService.GetByTicket(id); var ticketDiscussionGroupedByNote = _ticketDiscussionBusinessService.GetGroupedByNote(id) .GroupBy(q => q.TicketNoteId) .OrderBy(q => q.FirstOrDefault().CreatedAt) .ToList(); foreach (var items in ticketDiscussionGroupedByNote) { List <ApiJsonCommentTR> noteChild = new List <ApiJsonCommentTR>(); foreach (TicketDiscussion ticketDiscussion in items) { ApiJsonCommentDateTR apiJsonCommentDateTr1 = new ApiJsonCommentDateTR() { day = ticketDiscussion.CreatedAt?.ToString("dd MMM yyyy"), time = ticketDiscussion.CreatedAt?.ToString("hh:mm") }; ApiJsonCommentSenderTR apiJsonCommentSenderTr1 = new ApiJsonCommentSenderTR() { name = _userBusinessService.GetDetail(ticketDiscussion.UserId).Name, is_verified = true }; if (ticket.Responder == ticketDiscussion.UserId) { apiJsonCommentSenderTr1.type = "Responder"; } else { apiJsonCommentSenderTr1.type = "Admin"; if (isInParticipants(ticketParticipants, ticketDiscussion.UserId)) { apiJsonCommentSenderTr1.type = "Participant"; } if (ticket.Submiter == ticketDiscussion.UserId) { apiJsonCommentSenderTr1.type = "Submitter"; } } var attachments1 = _discussionAttachmentBusinessService.GetByDiscussionId(ticketDiscussion.TicketDiscussionId); List <ApiJsonCommentImageTR> listAttachment1 = new List <ApiJsonCommentImageTR>(); string attachmentsPath1 = "/Upload/Discussion/"; if (attachments1 != null) { foreach (var attachment in attachments1) { listAttachment1.Add(new ApiJsonCommentImageTR { src = WebConfigure.GetDomain() + attachmentsPath1 + attachment.Name, nama = attachment.Name }); } } ApiJsonCommentTR apiJsonCommentTrm1 = new ApiJsonCommentTR { id = ticketDiscussion.TicketDiscussionId, date = apiJsonCommentDateTr1, sender = apiJsonCommentSenderTr1, text = ticketDiscussion.Description, image = listAttachment1, isRemovable = (ticket.Responder == uid), type = ticketDiscussion.UserId == uid ? "sent" : "received" }; if (ticketDiscussion.TicketNoteId.Equals(0)) { apiJsonCommentTrml.Add(apiJsonCommentTrm1); } else { noteChild.Add(apiJsonCommentTrm1); } } var ticketNote = _ticketNoteBusinessService.GetDetail(items.Key); if (ticketNote != null) { ApiJsonCommentDateTR apiJsonCommentDateTr = new ApiJsonCommentDateTR() { day = ticketNote.CreatedAt?.ToString("dd MMM yyyy"), time = ticketNote.CreatedAt?.ToString("hh:mm") }; ApiJsonCommentSenderTR apiJsonCommentSenderTr = new ApiJsonCommentSenderTR() { name = _userBusinessService.GetDetail(ticketNote.UserId).Name, is_verified = true }; if (ticket.Responder == ticketNote.UserId) { apiJsonCommentSenderTr.type = "Responder"; } else { apiJsonCommentSenderTr.type = "Admin"; if (isInParticipants(ticketParticipants, ticketNote.UserId)) { apiJsonCommentSenderTr.type = "Participant"; } if (ticket.Submiter == ticketNote.UserId) { apiJsonCommentSenderTr.type = "Submitter"; } } var attachments = _noteAttachmentBusinessService.GetByNoteId(ticketNote.TicketNoteId); List <ApiJsonCommentImageTR> listAttachment = new List <ApiJsonCommentImageTR>(); string attachmentsPath = "/Upload/Note/"; if (attachments != null) { foreach (var attachment in attachments) { listAttachment.Add(new ApiJsonCommentImageTR { src = WebConfigure.GetDomain() + attachmentsPath + attachment.Name, nama = attachment.Name }); } } ApiJsonCommentTR apiJsonCommentTrm = new ApiJsonCommentTR() { type = "notes", date = apiJsonCommentDateTr, sender = apiJsonCommentSenderTr, text = ticketNote.Description, image = listAttachment, children = noteChild }; apiJsonCommentTrml.Add(apiJsonCommentTrm); } } apiJsonStatusM.code = 200; apiJsonStatusM.message = "Success Remove"; return(Ok(new { status = apiJsonStatusM, data = apiJsonCommentTrml })); } return(Json(new { status = new { code = 500, message = "Failed Remove" } })); }
public IHttpActionResult PostDiscussion() { if (!Common.GetAuthorization(Request)) { return(Ok(new { Code = 401, Message = "Unauthorization" })); } if (ModelState.IsValid) { var user = _userBusinessService.GetByToken(Request.Headers.GetValues("AccessToken").First()); if (user != null) { string msg = HttpContext.Current.Request.Params.Get("Description"); int typeMsg = int.Parse(HttpContext.Current.Request.Params.Get("Type")); int ticketId = int.Parse(HttpContext.Current.Request.Params.Get("TicketId")); int ticketDiscussionId = 0; int ticketNoteId = 0; DateTime dateTimeNow = DateTime.Now; Ticket ticket = _ticketBusinessService.GetDetail(ticketId); User userData = _userBusinessService.GetDetail(int.Parse(HttpContext.Current.Request.Params.Get("UserId"))); var dataUid = new List <int>(); var playerid = new List <string>(); var participants = _ticketParcipantBusinessService.GetByTicket(ticketId); TimeSpan respond = ticket.LastReply == null ? (DateTime.Now.Subtract(ticket.CreatedAt.Value)) : (DateTime.Now.Subtract(ticket.LastReply.Value)); if (typeMsg == 1) { TicketDiscussion ticketDiscussion = new TicketDiscussion() { TicketId = ticketId, CreatedAt = dateTimeNow, UserId = int.Parse(HttpContext.Current.Request.Params.Get("UserId")), Description = msg, TicketNoteId = 0,// -> new comment don't have note Status = 1, RespondTime = (respond.Days < 1 ? "" : respond.Days.ToString() + ". ") + respond.Hours.ToString() + ":" + respond.Minutes.ToString() + ":" + respond.Seconds.ToString() }; foreach (var i in participants) { dataUid.Add(i.UserId); } var iduserdevice = _ticketParcipantBusinessService.Getuserdeviceforasnote(dataUid); foreach (var p in iduserdevice) { playerid.Add(p.PlayerId); } playerid.Add(_userBusinessService.GetDetail(ticket.Responder).PlayerId); playerid.Add(_userBusinessService.GetDetail(ticket.Submiter).PlayerId); title = ticket.TicketNo + " - " + ticket.Title + " - Reply"; content = userData.Name + (ticket.Submiter == userData.UserId ? " (Submiter)" : ticket.Responder == userData.UserId ? " (Responder)" : " (Participant)") + " : " + msg; Onesignal.PushNotif(content, playerid, title, ticketId, ticket.TicketNo, ticket.TicketCategoryId, ticket.Description); ticketDiscussionId = _ticketDiscussionBusinessService.Add(ticketDiscussion).TicketDiscussionId; } else if (typeMsg == 2) { TicketNote ticketNote = new TicketNote() { TicketId = ticketId, CreatedAt = dateTimeNow, UserId = int.Parse(HttpContext.Current.Request.Params.Get("UserId")), Description = msg, Status = 1, RespondTime = (respond.Days < 1 ? "" : respond.Days.ToString() + ". ") + respond.Hours.ToString() + ":" + respond.Minutes.ToString() + ":" + respond.Seconds.ToString() }; foreach (var i in participants) { dataUid.Add(i.UserId); } var iduserdevice = _ticketParcipantBusinessService.Getuserdeviceforasnote(dataUid); foreach (var p in iduserdevice) { playerid.Add(p.PlayerId); } playerid.Add(_userBusinessService.GetDetail(ticket.Responder).PlayerId); playerid.Add(_userBusinessService.GetDetail(ticket.Submiter).PlayerId); title = ticket.TicketNo + " - " + ticket.Title + " - Reply As Note"; content = userData.Name + (ticket.Submiter == userData.UserId ? " (Submiter)" : " (Responder)") + " : " + msg; Onesignal.PushNotif(content, playerid, title, ticketId, ticket.TicketNo, ticket.TicketCategoryId, ticket.Description); ticketNoteId = _ticketNoteBusinessService.Add(ticketNote).TicketNoteId; _ticketDiscussionBusinessService.SetNote(ticketId, ticketNoteId); } if (HttpContext.Current.Request.Files.Count > 0) { for (int i = 0, iLen = HttpContext.Current.Request.Files.Count; i < iLen; i++) { string dateString = DateTime.Now.ToString("yyyyMMddHmmss"); var postedFile = HttpContext.Current.Request.Files[i]; switch (typeMsg) { case 1: // -> Comment var fileName = Path.GetFileName(postedFile.FileName); var path = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/Discussion/"), fileName); postedFile.SaveAs(path); DiscussionAttachment discussionAttachment = new DiscussionAttachment() { TicketDiscussionId = ticketDiscussionId, Name = fileName, Status = 1 }; _discussionAttachmentBusinessService.Add(discussionAttachment); break; default: // -> Note var fileNameNote = Path.GetFileName(postedFile.FileName); var pathNote = Path.Combine(HttpContext.Current.Server.MapPath("~/Upload/Note/"), fileNameNote); postedFile.SaveAs(pathNote); NoteAttachment noteAttachment = new NoteAttachment() { TicketNoteId = ticketNoteId, Name = fileNameNote, Status = 1 }; _noteAttachmentBusinessService.Add(noteAttachment); break; } } } List <ApiJsonCommentTR> apiJsonCommentTrList = new List <ApiJsonCommentTR>(); ApiJsonCommentDateTR apiJsonCommentDateTr = new ApiJsonCommentDateTR() { day = dateTimeNow.ToString("dddd, dd MMMM yyyy"), time = dateTimeNow.ToString("hh:mm") }; ApiJsonCommentSenderTR apiJsonCommentSenderTr = new ApiJsonCommentSenderTR() { name = _userBusinessService.GetDetail(int.Parse(HttpContext.Current.Request.Params.Get("UserId"))).Name, is_verified = true }; if (ticket.Responder == int.Parse(HttpContext.Current.Request.Params.Get("UserId"))) { apiJsonCommentSenderTr.type = "Responder"; if (typeMsg == 1) { ticket.LastReply = dateTimeNow; Ticket = _ticketBusinessService.Edit(ticket); } else if (typeMsg == 2) { ticket.NextCommenter = ticket.Submiter; ticket.LastStatusDate = dateTimeNow; ticket.LastReply = dateTimeNow; ticket.DueDateAnswer = dateTimeNow.AddDays(Common.NumberOfWorkDays(dateTimeNow, WebConfigure.GetRulesDay())); Ticket = _ticketBusinessService.Edit(ticket); } } else { if (ticket.Submiter == int.Parse(HttpContext.Current.Request.Params.Get("UserId"))) { apiJsonCommentSenderTr.type = "Submitter"; if (typeMsg == 1) { ticket.LastReply = dateTimeNow; Ticket = _ticketBusinessService.Edit(ticket); } else if (typeMsg == 2) { ticket.LastStatusDate = dateTimeNow; ticket.LastReply = dateTimeNow; ticket.NextCommenter = ticket.Responder; ticket.DueDateAnswer = DateTime.Now.AddDays(Common.NumberOfWorkDays(DateTime.Now, WebConfigure.GetRulesDay())); Ticket = _ticketBusinessService.Edit(ticket); } } else { apiJsonCommentSenderTr.type = "Participant"; ticket.LastReply = dateTimeNow; Ticket = _ticketBusinessService.Edit(ticket); } } List <ApiJsonCommentImageTR> listAttachment = new List <ApiJsonCommentImageTR>(); var attachments = _discussionAttachmentBusinessService.GetByDiscussionId(ticketDiscussionId); string attachmentsPath = System.Web.HttpContext.Current.Server.MapPath("~/Upload/Discussion/"); if (typeMsg == 2) { attachments = _noteAttachmentBusinessService.GetByNoteId(ticketNoteId); attachmentsPath = System.Web.HttpContext.Current.Server.MapPath("~/Upload/Note/"); } if (attachments != null) { foreach (var attachment in attachments) { listAttachment.Add(new ApiJsonCommentImageTR { src = WebConfigure.GetDomain() + "/Upload/TechnicalRequestAttachments/" + attachment.Name, Type = Path.GetExtension(attachment.Name), nama = attachment.Name }); } } ApiJsonCommentTR apiJsonCommentTr = new ApiJsonCommentTR() { date = apiJsonCommentDateTr, sender = apiJsonCommentSenderTr, text = msg, image = listAttachment }; switch (typeMsg) { case 1: apiJsonCommentTr.type = "sent"; break; default: apiJsonCommentTr.type = "notes"; break; } apiJsonCommentTrList.Add(apiJsonCommentTr); ApiJsonStatus apiJsonStatus = new ApiJsonStatus() { code = 200, message = "ok" }; if (typeMsg != 1) { if (ticket.TicketCategoryId != 9) { Email.GetEmailTagTsicsCommentTR(ticket); Email.GetEmailTagTsicsCommentTR(ticket, true); } else { Email.GetEmailTagTsicsCommentHelpDesk(ticketId, user.UserId, false); Email.GetEmailTagTsicsCommentHelpDesk(ticketId, user.UserId, true); } } return(Json(new { status = apiJsonStatus, data = apiJsonCommentTrList })); } else { _webStatus.code = 403; _webStatus.description = "Invalid AccessToken"; return(Ok(new { status = _webStatus, result = new object() })); } } return(BadRequest(ModelState)); }