コード例 #1
0
        public string AddFeedback(int projectID, int ticketID, string content, bool isPublic, bool isWaitClient,
                                  bool isWaitSunnetFeedback, string file, string clientsIds, HttpServerUtility Server)
        {
            try
            {
                ProjectsEntity  ProjectEntity   = projectApp.Get(projectID);
                FeedBacksEntity feedbacksEntity = GetFeedbacksEntity(ticketID, content, isPublic, isWaitClient, isWaitSunnetFeedback);
                TicketsEntity   ticket          = ticketApp.GetTickets(ticketID);

                var canAddWaiting = ticketApp.CanFeedbackWaiting(ticketID);
                if (!canAddWaiting)
                {
                    feedbacksEntity.WaitPMFeedback = feedbacksEntity.WaitClientFeedback = FeedbackReplyStatus.Normal;
                }

                string fileuploadErrMsg = string.Empty;

                feedbacksEntity.ID = fbAPP.AddFeedBacks(feedbacksEntity);
                if (feedbacksEntity.ID <= 0)
                {
                    var msg = fbAPP.BrokenRuleMessages != null && fbAPP.BrokenRuleMessages.Count > 0
                        ? fbAPP.BrokenRuleMessages[0].Message
                        : "";
                    return(ResponseMessage.GetResponse(false, msg));
                }

                // 产生气泡提示
                if (UserInfo.Role == RolesEnum.CLIENT || isPublic)
                {
                    ticketApp.CreateNotification(ticketID, UserInfo.UserID, false);
                }
                else
                {
                    ticketApp.CreateNotification(ticketID, UserInfo.UserID);
                }

                var extraStatus = new Dictionary <string, bool>();
                // 在添加FeedbackMessage时要更新Ticket 对相关人员的状态, 并且不能覆盖状态

                if (ticket.Status != TicketsState.Wait_Sunnet_Feedback &&
                    ticket.Status != TicketsState.Wait_Client_Feedback &&
                    canAddWaiting)
                {
                    if ((UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.Sales) && isWaitClient)
                    {
                        ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.WaitClientFeedback, UserID);
                        extraStatus.Add("waitSunnet", ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.WaitClientFeedback, TicketUsersType.Create));
                        new SendHandler(() => ticketStatusMgr.SendEmailtoClientForFeedBack(feedbacksEntity))
                        .BeginInvoke(null, null);

                        ProcessOtherClients(clientsIds, ticketID);
                    }
                    else if (UserInfo.Role == RolesEnum.CLIENT)
                    {
                        if (isWaitSunnetFeedback)
                        {
                            ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.WaitSunnetFeedback, UserID);
                            extraStatus.Add("waitClient", ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.WaitSunnetFeedback, TicketUsersType.PM));
                        }
                        new SendHandler(() => ticketStatusMgr.SendEmailtoPMForFeedBack(feedbacksEntity))
                        .BeginInvoke(null, null);
                    }
                }
                else
                {
                    // 相关状态人员可以通过回复清除自己的状态标识
                    if ((UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.Sales) && ticket.Status == TicketsState.Wait_Sunnet_Feedback && isPublic)
                    {
                        // Sunnet 直接清除PM的标识
                        if (ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.Normal, TicketUsersType.PM) &&
                            fbAPP.ReplyFeedback(ticketID, true, false))
                        {
                            ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.Normal, TicketUsersType.Create,
                                                         TicketUsersType.Client);
                            ticket.ResponsibleUser = PmReplyClient(ProjectEntity, ticket);
                            extraStatus.Add("clearSunnet", true);
                            var createrId = ticketApp.GetTicketCreateUser(ticketID);
                            var creater   = _userApp.GetUser(createrId.UserID);
                            new SendHandler(() => ticketStatusMgr.SendEmailFeedbackReplied(UserInfo, creater, ticketID))
                            .BeginInvoke(null, null);
                        }
                    }
                    if (UserInfo.Role == RolesEnum.CLIENT && ticket.Status == TicketsState.Wait_Client_Feedback)
                    {
                        // 客户方面只能清除自己的标识,因为可能需要多个客户回复
                        if (ticketApp.TryClearWaiting(ticketID, UserID, TicketUsersType.Create, TicketUsersType.Client) &&
                            fbAPP.ReplyFeedback(ticketID, false, true))
                        {
                            ticketApp.UpdateTicketStatus(ticketID, UserTicketStatus.Normal, TicketUsersType.PM);
                            extraStatus.Add("clearClient", true);
                            var pmId = ticketApp.GetTicketPM(ticketID);
                            var pm   = _userApp.GetUser(pmId.UserID);
                            new SendHandler(() => ticketStatusMgr.SendEmailFeedbackReplied(UserInfo, pm, ticketID))
                            .BeginInvoke(null, null);

                            ticketApp.DeleteUserFromTicket(ticketID, TicketUsersType.Client);
                        }
                    }
                }
                ticket.ModifiedOn = DateTime.Now;
                if (UserInfo.Role == RolesEnum.CLIENT && isWaitSunnetFeedback)
                {
                    ChangeResponsUserToProjectManager(ProjectEntity, ticket);
                }

                ticketApp.UpdateTickets(ticket, false);

                #region add file

                int      fileID       = 0;
                string   realFileName = "";
                string[] files        = file.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                Dictionary <string, int> uploadedFiles = new Dictionary <string, int>();
                foreach (var f in files)
                {
                    if ((fileID =
                             InsertFile(f, ProjectEntity.ProjectID, ticketID, feedbacksEntity.IsPublic,
                                        feedbacksEntity.ID, Server, out realFileName)) < 1)
                    {
                        fileuploadErrMsg += realFileName + " Upload failed.";
                    }
                    uploadedFiles.Add(realFileName, fileID);
                }

                #endregion

                if (string.IsNullOrEmpty(fileuploadErrMsg))
                {
                    ResponseMessage response = new ResponseMessage();
                    response.Success = true;

                    object attachement          = null;
                    object attachementBasicInfo = null;
                    if (uploadedFiles.Count > 0)
                    {
                        attachement = uploadedFiles;
                        string[] imgFormat = ".gif,.jpg,.jpeg,.bmp,.png,.svg,.raw".Split(new char[] { ',' });
                        attachementBasicInfo = uploadedFiles.Select(it => new
                        {
                            Key   = it.Key,
                            Value = imgFormat.Any(format => format == Path.GetExtension(it.Key.ToLower())) ? fileApp.Get(it.Value).FilePath : "/Images/icons/file.png"
                        }).ToDictionary(it => it.Key, it => it.Value);
                    }

                    feedbacksEntity.Description = new HtmlHelper().ReplaceUrl(feedbacksEntity.Description);

                    response.Data = new
                    {
                        content     = feedback.FormatHTML(feedbacksEntity.Description, Server).Replace("\n", "<br/>"),
                        id          = feedbacksEntity.ID,
                        date        = feedbacksEntity.CreatedOn.ToString("MM/dd/yyyy"),
                        time        = feedbacksEntity.CreatedOn.ToString("hh:mm tt"),
                        order       = feedbacksEntity.Order,
                        createdBy   = feedbacksEntity.CreatedBy,
                        firstname   = UserInfo.FirstName,
                        lastname    = UserInfo.LastName,
                        file        = attachement,
                        basicInfo   = attachementBasicInfo,
                        extraStatus = extraStatus,
                        tdCss       = feedbacksEntity.IsPublic && UserInfo.Role == RolesEnum.PM ? "fdcontentBox3" : "fdcontentBox2"
                    };

                    return(response.ToString());
                }
                else
                {
                    return(ResponseMessage.GetResponse(false, fileuploadErrMsg));
                }
            }
            catch (Exception ex)
            {
                WebLogAgent.Write(string.Format("Error Ascx:FeedbackList.ascx Messages:\r\n{0}", ex));
                return(ResponseMessage.GetResponse(false, ex.Message));
            }
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest  Request  = context.Request;
            HttpResponse Response = context.Response;

            context.Response.ContentType = "application/json";
            if (UserID <= 0)
            {
                Response.Write("[]");
                return;
            }
            string action = context.Request.Params["action"].ToLower();
            var    ticket = 0;
            var    user   = UserID;
            var    status = TicketUserStatus.None;

            var  targetUser = 0;
            var  update     = 0;
            bool flag       = true;

            switch (action)
            {
            case "setworkingon":
                int.TryParse(Request.Params["ticket"], out ticket);
                status = TicketUserStatus.WorkingOn;
                if (ticket > 0 && ticketApp.UpdateWorkingOnStatus(ticket, user, status))
                {
                    Response.Write(ResponseMessage.GetResponse(true));
                }
                else
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                }
                break;

            case "setworkingcomplete":
                int.TryParse(Request.Params["ticket"], out ticket);
                status = TicketUserStatus.Completed;
                if (ticket > 0 && ticketApp.UpdateWorkingOnStatus(ticket, user, status))
                {
                    Response.Write(ResponseMessage.GetResponse(true));
                }
                else
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                }
                break;

            case "setworkingcancelled":
                int.TryParse(Request.Params["ticket"], out ticket);
                status = TicketUserStatus.Canceled;
                if (ticket > 0 && ticketApp.UpdateWorkingOnStatus(ticket, user, status))
                {
                    Response.Write(ResponseMessage.GetResponse(true));
                }
                else
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                }
                break;

            case "setworkingonnone":
                int.TryParse(Request.Params["ticket"], out ticket);
                status = TicketUserStatus.None;
                if (ticket > 0 && ticketApp.UpdateWorkingOnStatus(ticket, user, status))
                {
                    Response.Write(ResponseMessage.GetResponse(true));
                }
                else
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                }
                break;

            case "set_client_notification_on":
                int.TryParse(Request.Params["ticket"], out ticket);
                int.TryParse(Request.Params["user"], out targetUser);
                if (ticket < 1 || targetUser < 1)
                {
                    Response.Write(ResponseMessage.GetResponse(false, "Arguments error."));
                    break;
                }
                if (!int.TryParse(Request.Params["update"], out update) || update < 1)
                {
                    if (ticketApp.IsTicketUser(ticket, UserID, TicketUsersType.Create, TicketUsersType.PM))
                    {
                        flag = ticketApp.AssignUsers(ticket, TicketUsersType.Client, targetUser);
                        if (flag)
                        {
                            new SendHandler(
                                () => ticketStatusApp.SendEmailtoClientForFeedBack(ticket, targetUser))
                            .BeginInvoke(null, null);
                        }
                    }
                    else
                    {
                        flag = false;
                    }
                }
                if (!flag)
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                    break;
                }
                //flag = ticketApp.UpdateNotification(ticket, targetUser);   // 更改状态去除气泡 提示
                //if (!flag)
                //{
                //    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                //    break;
                //}

                flag = ticketApp.UpdateTicketStatus(ticket, UserTicketStatus.WaitClientFeedback, targetUser);
                if (!flag)
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                    break;
                }
                if (UserInfo.Role == RolesEnum.PM)
                {
                    ticketApp.UpdateTicketStatus(ticket, UserTicketStatus.WaitClientFeedback, UserID);
                }
                new SendHandler(() => ticketStatusApp.SendEmailtoClientForFeedBack(ticket, targetUser)).BeginInvoke(null, null);

                Response.Write(ResponseMessage.GetResponse(true));
                break;

            case "set_client_notification_off":
                int.TryParse(Request.Params["ticket"], out ticket);
                int.TryParse(Request.Params["user"], out targetUser);
                if (ticket < 1 || targetUser < 1)
                {
                    Response.Write(ResponseMessage.GetResponse(false, "Arguments error."));
                    break;
                }
                if (!int.TryParse(Request.Params["update"], out update) || update < 1)
                {
                    Response.Write(ResponseMessage.GetResponse(true));
                    break;
                }
                else
                {
                    flag = true;
                }
                if (!flag)
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                    break;
                }

                ticketApp.UpdateTicketStatus(ticket, UserTicketStatus.Normal, targetUser);
                flag = ticketApp.DeleteUserFromTicket(ticket, targetUser);
                if (!flag)
                {
                    Response.Write(ResponseMessage.GetResponse(false, ticketApp.FirstBrokenRuleMessageContent));
                    break;
                }
                Response.Write(ResponseMessage.GetResponse(true));
                break;

            default:
                Response.Write("[]");
                break;
            }
        }