示例#1
0
        private void AddDefaultTicketUsers(ProjectsEntity projectsEntity, TicketsEntity ticketsEntity, int result, out List <int> userIds)
        {
            userIds = new List <int>();
            TicketUsersEntity ticketPMUserEntity = new TicketUsersEntity();

            //add pm user
            ticketPMUserEntity.Type     = TicketUsersType.PM;
            ticketPMUserEntity.TicketID = result;
            ProjectsEntity projectEntity = new ProjectApplication().Get(ticketsEntity.ProjectID);

            if (projectEntity != null)
            {
                ticketPMUserEntity.UserID = projectEntity.PMID;
                new TicketsApplication().AddTicketUser(ticketPMUserEntity);
                userIds.Add(projectEntity.PMID);
                //发送Email给Responsible
                ticketPMUserEntity.UserID = int.Parse(ddlRes.SelectedValue);
                new SendHandler(() => ex.SendEmailToResponsibile(ticketPMUserEntity, ticketsEntity, UserInfo)).BeginInvoke(null, null);
            }
            else
            {
                WebLogAgent.Write(string.Format("Add Pm To Ticket User Error:Project :{0},Ticket:{1},CreateDate:{2}",
                                                ticketsEntity.ProjectID, ticketsEntity.TicketID, DateTime.Now));
            }

            //add create user
            TicketUsersEntity ticketCreateUserEntity = new TicketUsersEntity();

            ticketCreateUserEntity.Type     = TicketUsersType.Create;
            ticketCreateUserEntity.TicketID = result;
            ticketCreateUserEntity.UserID   = ticketsEntity.CreatedBy;
            new TicketsApplication().AddTicketUser(ticketCreateUserEntity);

            if (userIds.Contains(ticketsEntity.CreatedBy) == false)
            {
                new SendHandler(() => ex.SendEmailToAssignedUser(ticketCreateUserEntity, ticketsEntity, UserInfo)).BeginInvoke(null, null);
                userIds.Add(ticketsEntity.CreatedBy);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            try
            {
                if (IdentityContext.UserID <= 0)
                {
                    return;
                }
                String        checkboxList = context.Request["checkboxList"];
                String        tid          = context.Request["tid"];
                String        type         = context.Request["type"];
                List <string> userArray    = new List <string>();
                List <string> userids      = new List <string>();
                List <string> userTypes    = new List <string>();


                if (!string.IsNullOrEmpty(checkboxList))
                {
                    userArray = checkboxList.Split(',').ToList();
                }

                foreach (string user in userArray)
                {
                    string[] values = user.Split('|');
                    userids.Add(values[0]);
                    userTypes.Add(values[1]);
                }

                IEnumerable <string> distinctedUserTypes = userTypes.Distinct();
                ticketApp.RemoveAllTicketUsersExceptPM(Convert.ToInt32(tid));//remove all ticket user
                TicketUsersEntity entity = new TicketUsersEntity();

                entity.TicketID = Convert.ToInt32(tid);
                int  result   = 0;
                bool HasError = false;
                for (int i = 0; i < userids.Count; i++)
                {
                    if (userids[i].Length > 0)
                    {
                        userID        = Convert.ToInt32(userids[i]);
                        entity.UserID = userID;
                        entity.Type   = (TicketUsersType)int.Parse(userTypes[i] + "");
                        result        = ticketApp.AddTicketUser(entity);
                        if (result > 0)
                        {
                            if (enableEmail)
                            {
                                ticketStatusMgr.SendEmailToAssignedUser(entity);
                            }
                        }
                        else
                        {
                            HasError = true;
                        }
                    }
                }
                if (!HasError)
                {
                    context.Response.Write("User Assign Successful!");
                }
                else
                {
                    context.Response.Write("User Assign Fail!");
                }
            }
            catch (Exception ex)
            {
                context.Response.Write("para error!");
                WebLogAgent.Write(string.Format("Error Ashx:DoAssignUserHandler.ashx Messages:\r\n{0}", ex));
                return;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            try
            {
                if (IdentityContext.UserID <= 0)
                {
                    return;
                }
                int result = 0;
                #region getValue

                int    pId           = Convert.ToInt32(context.Request["pId"]);
                string tType         = context.Request["tType"];
                string ckbEn         = context.Request["ckbEn"];
                string pty           = context.Request["pty"];
                string title         = context.Request["title"];
                string url           = context.Request["url"];
                string description   = context.Request["descr"];
                string imageList     = context.Request["imageList"];
                string imageSizeList = context.Request["imageSizeList"];
                string StartDate     = context.Request["StartDate"];
                string DeliveryDate  = context.Request["DeliveryDate"];
                string satus         = context.Request["satus"];
                string IsSunnet      = context.Request["isSunnet"];
                string userlist      = context.Request["userlist"];

                #endregion

                UsersEntity    entity         = userApp.GetUser(IdentityContext.UserID);
                ProjectsEntity projectsEntity = projectApp.Get(pId);

                #region add ticket
                TicketsEntity ticketEntity = new TicketsEntity();
                pty = string.IsNullOrEmpty(pty) ? "1" : pty;
                ticketEntity.ProjectID       = pId;
                ticketEntity.CompanyID       = projectsEntity.CompanyID;
                ticketEntity.Priority        = (PriorityState)Convert.ToInt32(pty);
                ticketEntity.TicketType      = (TicketsType)Convert.ToInt32(tType);
                ticketEntity.Title           = title.NoHTML();
                ticketEntity.URL             = context.Server.UrlEncode(url);
                ticketEntity.FullDescription = description.NoHTML();
                ticketEntity.CreatedBy       = IdentityContext.UserID;
                ticketEntity.CreatedOn       = DateTime.Now;
                ticketEntity.ModifiedOn      = DateTime.Now;

                ticketEntity.IsEstimates   = ckbEn == "checked" ? true : false;
                ticketEntity.TicketCode    = new TicketsApplication().ConvertTicketTypeToTicketCode(ticketEntity.TicketType);
                ticketEntity.IsInternal    = IsSunnet == "true" ? true : false;
                ticketEntity.ModifiedBy    = 0;
                ticketEntity.PublishDate   = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate();
                ticketEntity.ConvertDelete = CovertDeleteState.Normal;
                ticketEntity.Source        = entity.Role;
                if (IsSunnet == "true")
                {
                    ticketEntity.StartDate    = !string.IsNullOrEmpty(StartDate.ToString()) ? DateTime.Parse(StartDate).Date : UtilFactory.Helpers.CommonHelper.GetDefaultMinDate();
                    ticketEntity.DeliveryDate = !string.IsNullOrEmpty(DeliveryDate.ToString()) ? DateTime.Parse(DeliveryDate).Date : UtilFactory.Helpers.CommonHelper.GetDefaultMinDate();
                    if (entity.Role == RolesEnum.Supervisor)
                    {
                        ticketEntity.Status = TicketsState.Submitted;
                    }
                    else
                    {
                        ticketEntity.Status = TicketsState.PM_Reviewed;
                    }
                }
                else
                {
                    ticketEntity.StartDate    = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate();
                    ticketEntity.DeliveryDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate();
                    ticketEntity.Status       = satus == "0" ? TicketsState.Draft : TicketsState.Submitted;
                }

                result = ticketAPP.AddTickets(ticketEntity);

                if (result > 0)
                {
                    TicketUsersEntity ticketUserEntity = new TicketUsersEntity();
                    //add pm user
                    ticketUserEntity.Type     = TicketUsersType.PM;
                    ticketUserEntity.TicketID = result;
                    ProjectsEntity projectEntity = projectApp.Get(ticketEntity.ProjectID);
                    if (projectEntity != null)
                    {
                        ticketUserEntity.UserID = projectEntity.PMID;
                        ticketAPP.AddTicketUser(ticketUserEntity);
                    }
                    else
                    {
                        WebLogAgent.Write(string.Format("Add Pm To Ticket User Error:Project :{0},Ticket:{1},CreateDate:{2}",
                                                        ticketEntity.ProjectID, ticketEntity.TicketID, DateTime.Now));
                    }
                    //add create user
                    ticketUserEntity.Type     = TicketUsersType.Create;
                    ticketUserEntity.TicketID = result;
                    ticketUserEntity.UserID   = ticketEntity.CreatedBy;
                    ticketAPP.AddTicketUser(ticketUserEntity);
                }
                #endregion

                #region send email
                TicketStatusManagerApplication ex = new TicketStatusManagerApplication();
                if (!ticketEntity.IsInternal)
                {
                    ex.SendEmailToPMWhenTicketAdd(result, ticketEntity.TicketType);
                }

                #endregion

                #region add file

                FilesEntity fileEntity = new FilesEntity();

                if (null != projectsEntity)
                {
                    FolderName = projectsEntity.ProjectID.ToString();
                }

                string sNewFileName = "";

                tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];

                string[] listStringName = imageList.Split(',');

                string[] listStringSize = imageSizeList.Split(',');


                foreach (string Name in listStringName)
                {
                    if (Name.Length == 0)
                    {
                        break;
                    }
                    string sExtension = Path.GetExtension(Name).Replace(".", "").Trim();
                    foreach (string Size in listStringSize)
                    {
                        sNewFileName           = FolderName + Name;
                        fileEntity.ContentType = "." + sExtension.ToLower();
                        fileEntity.CreatedBy   = entity.UserID;
                        fileEntity.FilePath    = tempPath.Substring(2) + FolderName + @"/" + sNewFileName;
                        fileEntity.FileSize    = Convert.ToDecimal(Size.ToLower().Replace("kb", ""));
                        fileEntity.FileTitle   = Name.Substring(0, Name.LastIndexOf('.'));
                        fileEntity.IsPublic    = !ticketEntity.IsInternal;
                        fileEntity.ProjectId   = pId;
                        fileEntity.TicketId    = result;
                        fileEntity.CreatedOn   = DateTime.Now.Date;
                        fileEntity.FeedbackId  = 0;
                        fileEntity.SourceType  = (int)FileSourceType.Ticket;
                        fileEntity.ThumbPath   = context.Server.MapPath(tempPath) + FolderName + sNewFileName;;//
                        fileEntity.CompanyID   = IdentityContext.CompanyID;
                        int response = fileApp.AddFile(fileEntity);
                        if (response <= 0)
                        {
                            HasFileMsG = false;
                            stringErrorMsg.Add(fileEntity.FileTitle);
                        }
                        break;
                    }
                }

                #endregion

                #region response msg

                if (result > 0)
                {
                    if (HasFileMsG)
                    {
                        context.Response.Write("The ticket has been added.");
                    }
                    else
                    {
                        string error = "";
                        foreach (string item in stringErrorMsg)
                        {
                            error += item + "File Upload Failed!";
                        }
                        context.Response.Write(error);
                    }
                }
                else
                {
                    context.Response.Write("Add Fail!");
                }

                #endregion

                #region assign user and send email
                TicketUsersEntity tuEntity         = new TicketUsersEntity();;
                string[]          userWithRoleList = userlist.TrimEnd(',').Split(',');
                int assignResult = 0;
                if (userWithRoleList.Length > 0)
                {
                    foreach (string item in userWithRoleList)
                    {
                        if (item.Length > 0)
                        {
                            string[] userWithRole = item.Split('-');
                            if (userWithRole.Length > 0)
                            {
                                tuEntity.TicketID = result;
                                tuEntity.UserID   = Convert.ToInt32(userWithRole[0]);
                                tuEntity.Type     = GetUserTypeByRoleID(userWithRole[1]); //Convert.ToInt32(userWithRole[0]);
                                assignResult      = ticketAPP.AddTicketUser(tuEntity);
                                if (assignResult > 0)
                                {
                                    ex.SendEmailToAssignedUser(tuEntity);
                                }
                            }
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                context.Response.Write("Input special symbol is not allowed,please check title and description!");
                WebLogAgent.Write(string.Format("Error Ashx:DoAddTicketHandler.ashx Messages:\r\n{0}", ex));
                return;
            }
        }