public DTOTask RetrieveTask([FromBody] DTOTask paramDTOTask) { int intUserID = UtilitySecurity.UserIdFromUserName(this.User.Identity.Name, GetConnectionString()); bool IsAdministrator = UtilitySecurity.IsAdministrator(this.User.Identity.Name, GetConnectionString()); return(GetTask(paramDTOTask, intUserID, IsAdministrator, GetConnectionString(), this.User.Identity.Name, this.User.Identity.IsAuthenticated)); }
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())); }
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)); }
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()); }