Exemple #1
0
        public async Task <PartialViewResult> FilterList(
            string listName,
            int pageSize,
            int projectId,
            string ticketStatus,
            string owner,
            string assignedTo)
        {
            string   daterange = HttpContext.Request.Params.Get("daterange");
            DateTime toDate    = Convert.ToDateTime("01/01/" + DateTime.Now.Year);
            DateTime fromDate  = Convert.ToDateTime("12/31/" + DateTime.Now.Year);

            if (daterange != null && daterange.Length > 1)
            {
                List <string> lstTime = daterange.Split('-').ToList();
                toDate   = Convert.ToDateTime(lstTime[0]);
                fromDate = Convert.ToDateTime(lstTime[1]);
            }
            var uId         = Context.SecurityProvider.CurrentUserId;
            var userSetting = await Context.UserSettingsManager.GetSettingsForUserAsync(uId);

            if (userSetting != null && userSetting.ListSettings.Any())
            {
                for (int i = 0; i < userSetting.ListSettings.Count; i++)
                {
                    if (userSetting.ListSettings[i].ListName.ToLower().Equals(listName.ToString().ToLower()))
                    {
                        foreach (var item in userSetting.ListSettings[i].FilterColumns)
                        {
                            if (item.ColumnName.Equals("ToDate"))
                            {
                                item.ColumnValue = toDate.ToString("MM/dd/yyyy");
                            }
                            if (item.ColumnName.Equals("FromDate"))
                            {
                                item.ColumnValue = fromDate.ToString("MM/dd/yyyy");
                            }
                        }
                    }
                }
            }
            using (var tempCtx = new TdDomainContext())
            {
                await tempCtx.UserSettingsManager.AddOrUpdateSettingsForUser(userSetting);

                await tempCtx.SaveChangesAsync();
            }
            var currentListSetting = userSetting.GetUserListSettingByName(listName);

            currentListSetting.ModifyFilterSettings(pageSize, projectId, ticketStatus, owner, assignedTo, toDate, fromDate);//Tứ bổ sung projectId toDate, fromDate cho filter 13/03/2020

            await Context.SaveChangesAsync();

            return(await GetTicketListPartial(null, listName));
        }
 public async Task<UserSetting> GetSettingsForUserAsync(string userId)
 {
     var settings = await Context.UserSettings.FindAsync(userId);
     if (settings == null)
     {
         //settings for user not found, make default and save on separate context (so we don't commit other changes on this context as a side-effect).
         settings = UserSetting.GetDefaultSettingsForUser(userId, Context.SecurityProvider.IsTdHelpDeskUser || Context.SecurityProvider.IsTdAdministrator);
         using (var tempCtx = new TdDomainContext())
         {
             tempCtx.UserSettingsManager.AddSettingsForUser(settings);
             await tempCtx.SaveChangesAsync();
         }
     }
     return settings;
 }
Exemple #3
0
        public static async Task <int> GetUserSelectedProjectIdAsync(this UserSettingsManager userSettingsManager, TdDomainContext context)
        {
            //TODO: We have to take the source context as a param because we have sync callers (child action in navigation).
            //      Trying to use dependency resolver with a sync caller results in the context being invoked without a security provider.
            //      The entire concept of child actions are heavily refactored in MVC 6, so this should not be an issue in future versions.

            var projects = context.Projects;
            var settings = await userSettingsManager.GetSettingsForUserAsync(context.SecurityProvider.CurrentUserId);

            var projectId = settings.SelectedProjectId ?? 0;

            //if user's selected project points to a project that no longer exists, reset
            //  normally this wouldn't happen since the dbcontext will update user settings when projects are deleted
            if (projectId != 0 && await projects.AllAsync(p => p.ProjectId != projectId))
            {
                projectId = 0;
                await UpdateUserSelectedProjectAsync(userSettingsManager, projectId, context.SecurityProvider.CurrentUserId);

                await context.SaveChangesAsync();
            }
            return(projectId);
        }