Пример #1
0
        public HttpResponseMessage UpdateAgent(AgentViewModel agent)
        {
            try
            {
                var objAgentInfo = AgentManager.Instance.GetAgent(PortalSettings.PortalId, agent.AgentID);
                objAgentInfo.PortalID = PortalSettings.PortalId;
                objAgentInfo.Priority = agent.Priority;
                objAgentInfo.Enabled = agent.Enabled;
                AgentManager.Instance.UpdateAgent(objAgentInfo);

                DepartmentAgentManager.Instance.DeleteAgentDepartments(agent.AgentID);
                var departments = DepartmentManager.Instance.GetDepartments(PortalSettings.PortalId);
                foreach (var item in agent.Departments)
                {
                    var department = departments.FirstOrDefault(d => d.DepartmentName == item);
                    if (department == null) continue;
                    var objDepartmentAgentInfo = new DepartmentAgentInfo()
                    {
                        DepartmentID = department.DepartmentID,
                        AgentID = agent.AgentID,
                        UserID = agent.UserID
                    };
                    DepartmentAgentManager.Instance.AddDepartmentAgent(objDepartmentAgentInfo);
                }

                return Request.CreateResponse(HttpStatusCode.OK, new { Success = true });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
        }
Пример #2
0
        public HttpResponseMessage AddAgent(AgentViewModel agent)
        {
            try
            {
                if (agent.UserID == 0)
                    throw new Exception();

                Requires.NotNegative("agent.UserID", agent.UserID);

                var user = DotNetNuke.Entities.Users.UserController.GetUserById(PortalSettings.PortalId, agent.UserID);

                var objAgentInfo = new AgentInfo()
                {
                    PortalID = PortalSettings.PortalId,
                    UserID = agent.UserID,
                    Priority = agent.Priority,
                    Enabled = agent.Enabled,
                    CreateByUser = UserInfo.UserID,
                    CreateDate = DateTime.Now
                };
                int agentID = AgentManager.Instance.AddAgent(objAgentInfo);
                agent.AgentID = agentID;

                if (!user.IsInRole("MyDnnSupportAgent"))
                {
                    var role = RoleController.Instance.GetRoleByName(PortalSettings.PortalId, "MyDnnSupportAgent");
                    RoleController.AddUserRole(user, role, PortalSettings, DotNetNuke.Security.Roles.RoleStatus.Approved, Null.NullDate, Null.NullDate, true, false);
                }

                var departments = DepartmentManager.Instance.GetDepartments(PortalSettings.PortalId);
                foreach (var item in agent.Departments)
                {
                    var department = departments.FirstOrDefault(d => d.DepartmentName == item);
                    if (department == null) continue;
                    var objDepartmentAgentInfo = new DepartmentAgentInfo()
                    {
                        DepartmentID = department.DepartmentID,
                        AgentID = agentID,
                        UserID = agent.UserID
                    };
                    DepartmentAgentManager.Instance.AddDepartmentAgent(objDepartmentAgentInfo);
                }

                agent.Email = user.Email;

                return Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Agent = agent });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                string msg = ex.Message;

                if (((System.Data.SqlClient.SqlException)(ex)).Number == 2627) // user entekhab shode ghablan dar system be onvane agent sabt shode ast
                    msg = string.Format(Localization.Instance.GetString(DotNetNuke.Common.Globals.ResolveUrl("~/MyDnnPackage/dnn8contest/Website/DesktopModules/MVC/MyDnnSupport/LiveChat/App_LocalResources/SharedResources"), PortalSettings.CultureCode, "DuplicateAgent.Text"), agent.DisplayName);

                return Request.CreateResponse(HttpStatusCode.InternalServerError, msg);
            }
        }