public TaskSearchResult SearchTasks([FromBody] SearchTaskParameters searchData)
        {
            // Get UserID
            int intUserId = UtilitySecurity.UserIdFromUserName(this.User.Identity.Name, GetConnectionString());

            // Determine if user is an Admin
            int iSAdministrator = (UtilitySecurity.IsAdministrator(this.User.Identity.Name, GetConnectionString())) ? 1 : 0;

            return(SearchTasks(searchData, intUserId, iSAdministrator, GetConnectionString()));
        }
示例#2
0
        public TaskSearchResult SearchTasks([FromBody] SearchParameters searchData)
        {
            SearchTaskParameters objSearchTaskParameters = new SearchTaskParameters();

            objSearchTaskParameters.assignedRoleId    = searchData.assignedRoleId;
            objSearchTaskParameters.createdDate       = searchData.createdDate;
            objSearchTaskParameters.dueDate           = searchData.dueDate;
            objSearchTaskParameters.pageNumber        = searchData.pageNumber;
            objSearchTaskParameters.priority          = searchData.priority;
            objSearchTaskParameters.rowsPerPage       = searchData.rowsPerPage;
            objSearchTaskParameters.searchText        = searchData.searchText;
            objSearchTaskParameters.selectedTreeNodes = searchData.selectedTreeNodes;
            objSearchTaskParameters.sortField         = searchData.sortField;
            objSearchTaskParameters.sortOrder         = searchData.sortOrder;
            objSearchTaskParameters.status            = searchData.status;
            objSearchTaskParameters.userId            = "-1";
            objSearchTaskParameters.id = "-1";

            return(TaskController.SearchTasks(objSearchTaskParameters, -1, 1, GetConnectionString()));
        }
示例#3
0
        public IActionResult Index()
        {
            // SearchTaskParameters to return
            // Set important defaults
            SearchTaskParameters objSearchTaskParameters = new SearchTaskParameters();

            objSearchTaskParameters.priority    = "";
            objSearchTaskParameters.searchText  = "";
            objSearchTaskParameters.status      = "";
            objSearchTaskParameters.pageNumber  = 1;
            objSearchTaskParameters.rowsPerPage = 10;

            // See if the user is logged in
            if (this.User.Identity.IsAuthenticated)
            {
                // Get UserId
                int UserId = UtilitySecurity.UserIdFromUserName(this.User.Identity.Name, GetConnectionString());

                // Get the LastSearch
                var optionsBuilder = new DbContextOptionsBuilder <ADefHelpDeskContext>();
                optionsBuilder.UseSqlServer(GetConnectionString());

                using (var context = new ADefHelpDeskContext(optionsBuilder.Options))
                {
                    var objLastSearch = context.AdefHelpDeskLastSearch
                                        .Where(x => x.UserId == UserId)
                                        .FirstOrDefault();

                    if (objLastSearch != null)
                    {
                        objSearchTaskParameters.id             = objLastSearch.Id.ToString();
                        objSearchTaskParameters.userId         = objLastSearch.UserId.ToString();
                        objSearchTaskParameters.assignedRoleId = objLastSearch.AssignedRoleId != null?objLastSearch.AssignedRoleId.ToString() : "";

                        objSearchTaskParameters.searchText = objLastSearch.SearchText != null?objLastSearch.SearchText.ToString() : "";

                        objSearchTaskParameters.status = objLastSearch.Status != null?objLastSearch.Status.ToString() : "";

                        objSearchTaskParameters.createdDate = objLastSearch.CreatedDate != null?objLastSearch.CreatedDate.Value.ToShortDateString() : "";

                        objSearchTaskParameters.dueDate = objLastSearch.DueDate != null?objLastSearch.DueDate.Value.ToShortDateString() : "";

                        objSearchTaskParameters.priority = objLastSearch.Priority != null?objLastSearch.Priority.ToString() : "";

                        objSearchTaskParameters.pageNumber  = objLastSearch.CurrentPage ?? -1;
                        objSearchTaskParameters.rowsPerPage = objLastSearch.PageSize ?? -1;

                        // Categories (selectedTreeNodes)
                        objSearchTaskParameters.selectedTreeNodes = new List <int>();

                        if (objLastSearch.Categories != null)
                        {
                            string[] Categories = objLastSearch.Categories.Split(",");
                            foreach (var Category in Categories)
                            {
                                if (Category.Trim().Length > 0)
                                {
                                    objSearchTaskParameters.selectedTreeNodes.Add(Convert.ToInt32(Category));
                                }
                            }
                        }
                    }
                }
            }

            // Return the result
            return(Ok(objSearchTaskParameters));
        }
        // Private Methods

        #region public static TaskSearchResult SearchTasks(SearchTaskParameters searchData, int intUserId, int iSAdministrator, string DefaultConnection)
        public static TaskSearchResult SearchTasks(SearchTaskParameters searchData, int intUserId, int iSAdministrator, string DefaultConnection)
        {
            TaskSearchResult objTaskSearchResult = new TaskSearchResult();

            objTaskSearchResult.taskList = new List <DTOTask>();
            List <AdefHelpDeskRoles> AllRoles = new List <AdefHelpDeskRoles>();
            var resultTable = new DataTable();

            //If searchData.rowsPerPage = 0 set it to 1
            if (searchData.rowsPerPage == 0)
            {
                searchData.rowsPerPage = 1;
            }

            //If searchData.pageNumber = 0 set it to 1
            if (searchData.pageNumber == 0)
            {
                searchData.pageNumber = 1;
            }

            var optionsBuilder = new DbContextOptionsBuilder <ADefHelpDeskContext>();

            optionsBuilder.UseSqlServer(DefaultConnection);

            using (var context = new ADefHelpDeskContext(optionsBuilder.Options))
            {
                // Get all possible roles to reduce database calls later
                AllRoles = (from role in context.AdefHelpDeskRoles
                            select role).ToList();
            }

            using (var conn = new SqlConnection(DefaultConnection))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.CommandText = "[spSearchTasks]";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = conn;

                    cmd.Parameters.AddWithValue("@paramIsAdmin", iSAdministrator);
                    cmd.Parameters.AddWithValue("@paramUserId", intUserId);
                    cmd.Parameters.AddWithValue("@paramSearchText", searchData.searchText ?? "");
                    cmd.Parameters.AddWithValue("@paramStatus", searchData.status ?? "");
                    cmd.Parameters.AddWithValue("@paramPriority", searchData.priority ?? "");
                    cmd.Parameters.AddWithValue("@paramCreatedDate", searchData.createdDate ?? "");
                    cmd.Parameters.AddWithValue("@paramDueDate", searchData.dueDate ?? "");
                    cmd.Parameters.AddWithValue("@paramAssignedRoleId", searchData.assignedRoleId ?? "");
                    cmd.Parameters.AddWithValue("@paramSelectedTreeNodes", String.Join(",", searchData.selectedTreeNodes));
                    cmd.Parameters.AddWithValue("@paramSortOrder", searchData.sortOrder ?? "");
                    cmd.Parameters.AddWithValue("@paramSortField", searchData.sortField ?? "");
                    cmd.Parameters.AddWithValue("@paramRowsPerPage", searchData.rowsPerPage);
                    cmd.Parameters.AddWithValue("@paramPageNumber", searchData.pageNumber);

                    SqlParameter parTotalCount = new SqlParameter("@paramTotalCount", SqlDbType.Int);
                    parTotalCount.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(parTotalCount);

                    using (var adapter = new SqlDataAdapter(cmd))
                    {
                        adapter.Fill(resultTable);
                    }

                    objTaskSearchResult.totalRows = Convert.ToInt32(parTotalCount.Value);
                }
            }

            List <DTOTask> colDTOTasks = new List <DTOTask>();

            foreach (System.Data.DataRow item in resultTable.Rows)
            {
                DTOTask objDTOTask = new DTOTask();

                objDTOTask.taskId              = Convert.ToInt32(item.ItemArray[0]);
                objDTOTask.portalId            = Convert.ToInt32(item.ItemArray[1]);
                objDTOTask.description         = Convert.ToString(item.ItemArray[2]);
                objDTOTask.status              = Convert.ToString(item.ItemArray[3]);
                objDTOTask.priority            = Convert.ToString(item.ItemArray[4]);
                objDTOTask.createdDate         = Convert.ToDateTime(item.ItemArray[5]).ToShortDateString();
                objDTOTask.estimatedStart      = (item.ItemArray[6].ToString() != "") ? Convert.ToDateTime(item.ItemArray[6]).ToShortDateString() : "";
                objDTOTask.estimatedCompletion = (item.ItemArray[7].ToString() != "") ? Convert.ToDateTime(item.ItemArray[7]).ToShortDateString() : "";
                objDTOTask.dueDate             = (item.ItemArray[8].ToString() != "") ? Convert.ToDateTime(item.ItemArray[8]).ToShortDateString() : "";
                objDTOTask.assignedRoleId      = Convert.ToInt32(item.ItemArray[9]);
                objDTOTask.ticketPassword      = Convert.ToString(item.ItemArray[10]);
                objDTOTask.requesterUserId     = Convert.ToInt32(item.ItemArray[11]);
                objDTOTask.requesterName       = Convert.ToString(item.ItemArray[12]);
                objDTOTask.requesterEmail      = Convert.ToString(item.ItemArray[13]);
                objDTOTask.requesterPhone      = Convert.ToString(item.ItemArray[14]);
                if (item.ItemArray[15].ToString() != "")
                {
                    objDTOTask.estimatedHours = Convert.ToInt32(item.ItemArray[15]);
                }

                // Set Requester Name
                if (objDTOTask.requesterUserId > 0)
                {
                    var User = UtilitySecurity.UserFromUserId(objDTOTask.requesterUserId.Value, DefaultConnection);
                    objDTOTask.requesterName = $"{User.firstName} {User.lastName}";
                }
                else
                {
                    objDTOTask.requesterName = objDTOTask.requesterName;
                }

                // Set AssignedRoleName
                var objUserRole = AllRoles.Where(x => x.Id == objDTOTask.assignedRoleId).FirstOrDefault();
                if (objUserRole != null)
                {
                    objDTOTask.assignedRoleName = objUserRole.RoleName;
                }
                else
                {
                    objDTOTask.assignedRoleName = "[Unassigned]";
                }

                colDTOTasks.Add(objDTOTask);
            }

            objTaskSearchResult.taskList     = colDTOTasks;
            objTaskSearchResult.errorMessage = string.Empty;

            return(objTaskSearchResult);
        }
示例#5
0
        public IActionResult SaveSearchParameters([FromBody] SearchTaskParameters paramSearchTaskParameters)
        {
            // See if the user is logged in
            try
            {
                if (this.User.Identity.IsAuthenticated)
                {
                    // Get UserId
                    int UserId = UtilitySecurity.UserIdFromUserName(this.User.Identity.Name, GetConnectionString());

                    var optionsBuilder = new DbContextOptionsBuilder <ADefHelpDeskContext>();
                    optionsBuilder.UseSqlServer(GetConnectionString());

                    using (var context = new ADefHelpDeskContext(optionsBuilder.Options))
                    {
                        // First remove any existing records for the user
                        context.AdefHelpDeskLastSearch.RemoveRange(context.AdefHelpDeskLastSearch.Where(x => x.UserId == UserId));
                        context.SaveChanges();

                        AdefHelpDeskLastSearch objNewLastSearch = new AdefHelpDeskLastSearch();

                        objNewLastSearch.UserId      = UserId;
                        objNewLastSearch.SearchText  = (paramSearchTaskParameters.searchText != null) ? paramSearchTaskParameters.searchText.Trim() : "";
                        objNewLastSearch.Status      = (paramSearchTaskParameters.status != null) ? paramSearchTaskParameters.status.Trim() : "";
                        objNewLastSearch.Priority    = (paramSearchTaskParameters.priority != null) ? paramSearchTaskParameters.priority.Trim() : "";
                        objNewLastSearch.CurrentPage = paramSearchTaskParameters.pageNumber;
                        objNewLastSearch.PageSize    = paramSearchTaskParameters.rowsPerPage;

                        if (paramSearchTaskParameters.userId != null)
                        {
                            objNewLastSearch.UserId = Convert.ToInt32(paramSearchTaskParameters.userId);
                        }

                        if (paramSearchTaskParameters.assignedRoleId != null)
                        {
                            objNewLastSearch.AssignedRoleId = Convert.ToInt32(paramSearchTaskParameters.assignedRoleId);
                        }

                        if (paramSearchTaskParameters.createdDate != null)
                        {
                            objNewLastSearch.CreatedDate = Utility.CastToDate(paramSearchTaskParameters.createdDate);
                        }

                        if (paramSearchTaskParameters.dueDate != null)
                        {
                            objNewLastSearch.DueDate = Utility.CastToDate(paramSearchTaskParameters.dueDate);
                        }

                        objNewLastSearch.Categories = string.Join(",", paramSearchTaskParameters.selectedTreeNodes);

                        // Save changes
                        context.AdefHelpDeskLastSearch.Add(objNewLastSearch);
                        context.SaveChanges();
                    }
                }
            }
            catch
            {
                // Do nothing if search paramaters cannot be saved
            }

            return(NoContent());
        }