Esempio n. 1
0
        //[FunctionalityAutorizeAttribute("USERS_MANAGEMENT")]
        public JsonResult Get()
        {
            var data = BusinessItemsLists.GetUsers();

            data.ForEach(i => i.ProfilePhoto = null);
            string editUrl   = this.HttpContext.Request.Path.Replace("Get", "Edit") + "/";
            string deleteUrl = this.HttpContext.Request.Path.Replace("Get", "Delete") + "/";

            //data.ForEach(i => i.Controlo = "<button  onclick=\"$('#urlField').val('" + editUrl + i.ID.ToString() + "');$('.ui-dialog-title').html('Edit');$('#dialog-edit').dialog('open');return false;\" >" + Resources.Resources.Edit + "</button><button  onclick=\"$('#urlField').val('" + deleteUrl + i.ID.ToString() + "');$('#dialog-confirm').dialog('open');$('.date-picker').datepicker();return false;\" >" + Resources.Resources.Delete + "</button>");
            data.ForEach(i => i.Controlo = "<input class=\"jsgrid-button jsgrid-edit-button\" type=\"button\" title=\"Edit\" onclick=\"$('#urlField').val('" + editUrl + i.ID.ToString() + "');$('.ui-dialog-title').html('Edit');$('#dialog-edit').dialog('open');return false;\"><input class=\"jsgrid-button jsgrid-delete-button\" type=\"button\" title=\"Delete\" onclick=\"openConfirmUserDelete(" + i.ID.ToString() + ")\">");
            data.ForEach(i => i.Active   = !i.User.LockoutEndDateUtc.HasValue);
            //data.ForEach(i => i.CreateDateString = string.Format("{0}-{1}-{2}", i.CreateDate.Day.ToString("00"), i.CreateDate.Month.ToString("00"), i.CreateDate.Year));
            data.ForEach(i => i.CreateDateString = string.Format("{2}-{1}-{0}T{3}:{4}:{5}", i.CreateDate.Day.ToString("00"), i.CreateDate.Month.ToString("00"), i.CreateDate.Year, i.CreateDate.Hour.ToString("00"), i.CreateDate.Minute.ToString("00"), i.CreateDate.Second.ToString("00")));

            return(Json(data.ToArray(), JsonRequestBehavior.AllowGet));

            //return new JsonResult()
            //{
            //    Data = BusinessItemsLists.GetUsers().ToArray(),
            //    ContentType = "application/json",
            //    //ContentEncoding = contentEncoding,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
            //    MaxJsonLength = Int32.MaxValue
            //};

            //return Json(BusinessItemsLists.GetUsers().ToArray(), JsonRequestBehavior.AllowGet);
        }
Esempio n. 2
0
        public async Task <ActionResult> Index(long?ntId)
        {
            if (ntId.HasValue)
            {
                InsuranceBusiness.BusinessLayer.MarkNotificationAsRead(ntId.Value);
            }

            UsersManagementViewModel model = new UsersManagementViewModel();

            if (null != this.User && this.User.Identity.IsAuthenticated)
            {
                var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var user        = await UserManager.FindByNameAsync(this.User.Identity.Name);

                if (null != user)
                {
                    FillModel(model, user.Id, false);
                    //model.Profile = InsuranceBusiness.BusinessLayer.GetUserProfile(user.Id);
                }
                else
                {
                    return(RedirectToAction("LogOff", "Account"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }

            try
            {
                var grid = MVCGridDefinitionTable.GetDefinition <UserProfileModelObject>("UsersManagementGrid");
            }
            catch (Exception)
            {
                MVCGridDefinitionTable.Add("UsersManagementGrid", new MVCGridBuilder <UserProfileModelObject>()
                                           .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                                           //.WithSorting(sorting: true, defaultSortColumn: "Id", defaultSortDirection: SortDirection.Dsc)
                                           .AddColumns(cols =>
                {
                    // Add your columns here
                    cols.Add().WithColumnName("FirstName")
                    .WithHeaderText(Resources.Resources.FirstName)
                    .WithValueExpression(i => i.FirstName)
                    .WithAllowChangeVisibility(true)
                    .WithFiltering(true)
                    .WithSorting(true)
                    .WithVisibility(true, true);     // use the Value Expression to return the cell text for this column
                    cols.Add().WithColumnName("LastName")
                    .WithHeaderText(Resources.Resources.LastName)
                    .WithValueExpression(i => i.LastName)
                    .WithAllowChangeVisibility(true)
                    .WithFiltering(true)
                    .WithSorting(true)
                    .WithVisibility(true, true);     // use the Value Expression to return the cell text for this column
                    cols.Add().WithColumnName("Username")
                    .WithHeaderText(Resources.Resources.Email)
                    .WithValueExpression(i => i.User.UserName)
                    .WithAllowChangeVisibility(true)
                    .WithFiltering(true)
                    .WithSorting(true)
                    .WithVisibility(true, true);     // use the Value Expression to return the cell text for this column
                    cols.Add().WithColumnName("ProfessionalNumber")
                    .WithHeaderText(Resources.Resources.ProfessionalNumber)
                    .WithValueExpression(i => i.ProfessionalNumber)
                    .WithAllowChangeVisibility(true)
                    .WithFiltering(true)
                    .WithSorting(true)
                    .WithVisibility(true, true);     // use the Value Expression to return the cell text for this column
                    cols.Add("CreateDate")
                    .WithSorting(true)
                    .WithHeaderText(Resources.Resources.RegisterDate)
                    .WithCellCssClassExpression(p => "dateCell")
                    .WithValueExpression(p => p.CreateDate.ToString("dd-MM-yyyy"))
                    .WithVisibility(true, true);
                    cols.Add("Active").WithHtmlEncoding(false)
                    .WithSorting(true)
                    .WithHeaderText(Resources.Resources.Active)
                    .WithValueExpression((p, c) => !p.User.LockoutEndDateUtc.HasValue ? "checked" : "")
                    .WithValueTemplate("<input type=\"checkbox\" disabled=\"disabled\" {Value}>")
                    .WithCellCssClassExpression(p => "mvcgrid-cell")
                    .WithVisibility(true, true);
                    cols.Add("Edit").WithHtmlEncoding(false)
                    .WithSorting(false)
                    .WithHeaderText(" ")
                    .WithValueExpression((p, c) => c.UrlHelper.Action("Edit", "UsersManagement", new { id = p.ID }))
                    .WithValueTemplate("<a href='{Value}' class='btn btn-warning lnkEdit'>" + Resources.Resources.Edit + "</a>")
                    .WithVisibility(true, false);
                    cols.Add("Delete").WithHtmlEncoding(false)
                    .WithSorting(false)
                    .WithHeaderText(" ")
                    .WithValueExpression((p, c) => c.UrlHelper.Action("Delete", "UsersManagement", new { id = p.ID }))
                    .WithValueTemplate("<a href='{Value}' class='btn btn-danger lnkDelete' role='button'>" + Resources.Resources.Delete + "</a>")
                    .WithVisibility(true, false);
                })
                                           .WithAdditionalQueryOptionNames("Search")
                                           .WithSorting(true, "FirstName")
                                           .WithPaging(paging: true, itemsPerPage: 100, allowChangePageSize: true, maxItemsPerPage: 100)
                                           .WithProcessingMessage(Resources.Resources.Loading)
                                           .WithNextButtonCaption(Resources.Resources.Next)
                                           .WithPreviousButtonCaption(Resources.Resources.Previous)
                                           .WithSummaryMessage(Resources.Resources.ShowingGridEntries)
                                           .WithRetrieveDataMethod((context) =>
                {
                    // Query your data here. Obey Ordering, paging and filtering parameters given in the context.QueryOptions.
                    // Use Entity Framework, a module from your IoC Container, or any other method.
                    // Return QueryResult object containing IEnumerable<YouModelItem>

                    var options = context.QueryOptions;
                    var result  = new QueryResult <UserProfileModelObject>();
                    var query   = BusinessItemsLists.GetUsers();
                    if (!String.IsNullOrWhiteSpace(options.SortColumnName))
                    {
                        switch (options.SortColumnName.ToLower())
                        {
                        case "firstname":
                            if (options.SortDirection == SortDirection.Asc ||
                                options.SortDirection == SortDirection.Unspecified)
                            {
                                query = query.OrderBy(p => p.FirstName).ToList();
                            }
                            else
                            {
                                query = query.OrderByDescending(p => p.FirstName).ToList();
                            }

                            break;

                        case "lastname":
                            if (options.SortDirection == SortDirection.Asc ||
                                options.SortDirection == SortDirection.Unspecified)
                            {
                                query = query.OrderBy(p => p.LastName).ToList();
                            }
                            else
                            {
                                query = query.OrderByDescending(p => p.LastName).ToList();
                            }

                            break;

                        case "username":
                            if (options.SortDirection == SortDirection.Asc ||
                                options.SortDirection == SortDirection.Unspecified)
                            {
                                query = query.OrderBy(p => p.User.UserName).ToList();
                            }
                            else
                            {
                                query = query.OrderByDescending(p => p.User.UserName).ToList();
                            }

                            break;

                        case "active":
                            if (options.SortDirection == SortDirection.Asc ||
                                options.SortDirection == SortDirection.Unspecified)
                            {
                                query = query.OrderBy(p => p.Active).ToList();
                            }
                            else
                            {
                                query = query.OrderByDescending(p => p.Active).ToList();
                            }

                            break;

                        case "createdate":
                            if (options.SortDirection == SortDirection.Asc ||
                                options.SortDirection == SortDirection.Unspecified)
                            {
                                query = query.OrderBy(p => p.CreateDate).ToList();
                            }
                            else
                            {
                                query = query.OrderByDescending(p => p.CreateDate).ToList();
                            }

                            break;
                        }
                    }

                    string globalSearch = options.GetAdditionalQueryOptionString("Search");
                    if (null != globalSearch)
                    {
                        query = query.Where(i =>
                                            (null != i.FirstName && i.FirstName.ToLower().Contains(globalSearch.ToLower())) ||
                                            (null != i.LastName && i.LastName.ToLower().Contains(globalSearch.ToLower())) ||
                                            (null != i.User && null != i.User.UserName && i.User.UserName.ToLower().Contains(globalSearch.ToLower()))
                                            //|| (null != i.ContactEmail && i.ContactEmail.Contains(globalSearch))
                                            ).ToList();
                    }

                    result.TotalRecords = query.Count();

                    if (options.GetLimitOffset().HasValue)
                    {
                        query = query
                                .Skip(options.GetLimitOffset().Value)
                                .Take(options.GetLimitRowcount().Value)
                                .ToList();
                    }

                    result.Items = query;

                    return(result);

                    //return new QueryResult<UserProfileModelObject>()
                    //{
                    //    Items = query,
                    //    TotalRecords = query.Count // if paging is enabled, return the total number of records of all pages
                    //};
                })
                                           );
            }

            return(View(model));
        }
Esempio n. 3
0
        public async Task <ActionResult> Index()
        {
            RolesManagementViewModel model = new RolesManagementViewModel();

            if (null != this.User && this.User.Identity.IsAuthenticated)
            {
                var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var user        = await UserManager.FindByNameAsync(this.User.Identity.Name);

                if (null != user)
                {
                    model.Profile = InsuranceBusiness.BusinessLayer.GetUserProfile(user.Id);
                }
                else
                {
                    return(RedirectToAction("LogOff", "Account"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }

            try
            {
                //var grid = MVCGridDefinitionTable.GetDefinition<UserProfileModelObject>("RolesManagementGrid");
            }
            catch (Exception)
            {
                MVCGridDefinitionTable.Add("RolesManagementGrid", new MVCGridBuilder <UserProfileModelObject>()
                                           .WithAuthorizationType(AuthorizationType.AllowAnonymous)
                                           .AddColumns(cols =>
                {
                    // Add your columns here
                    cols.Add().WithColumnName("Username")
                    .WithHeaderText(Resources.Resources.Username)
                    .WithValueExpression(i => i.User.UserName)
                    .WithAllowChangeVisibility(true)
                    .WithFiltering(true)
                    .WithSorting(true)
                    .WithVisibility(true, true);             // use the Value Expression to return the cell text for this column
                    cols.Add().WithColumnName("FirstName")
                    .WithHeaderText(Resources.Resources.Name)
                    .WithValueExpression(i => i.FirstName)
                    .WithAllowChangeVisibility(true)
                    .WithFiltering(true)
                    .WithSorting(true)
                    .WithVisibility(true, true);             // use the Value Expression to return the cell text for this column
                    cols.Add("CreateDate")
                    .WithHeaderText(Resources.Resources.RegisterDate)
                    .WithCellCssClassExpression(p => "dateCell")
                    .WithValueExpression(p => p.CreateDate.ToString("dd-MM-yyyy"));
                    cols.Add("Activate")
                    .WithHtmlEncoding(false)
                    .WithSorting(false)
                    .WithHeaderText(" ")
                    .WithCellCssClassExpression(p => "controlCell")
                    //.WithPlainTextValueExpression((p, c) => p.User.EmailConfirmed ? "deactivate" : "activate")
                    .WithValueExpression((p, c) => c.UrlHelper.Action(p.User.EmailConfirmed ? "Deactivate" : "Activate", "UsersManagement", new { id = p.ID }))
                    .WithValueTemplate("<a href='{Value}' class='' role='button' style='margin-right:5px;color:limegreen;'>" + MVCGridConfig.GetActivateCommandCode("{Model.User.EmailConfirmed}") + "</a>" + "<a href='UsersManagement/BlockUser/{Model.ID}' class='' role='button' style='margin-right:5px;color:red'>" + MVCGridConfig.GetBlockCommandCode("{Model.User.EmailConfirmed}") + "</a>");
                })
                                           .WithAdditionalQueryOptionNames("Search")
                                           .WithSorting(true, "FirstName")
                                           .WithPaging(paging: true, itemsPerPage: 10, allowChangePageSize: true, maxItemsPerPage: 100)
                                           .WithRetrieveDataMethod((context) =>
                {
                    // Query your data here. Obey Ordering, paging and filtering parameters given in the context.QueryOptions.
                    // Use Entity Framework, a module from your IoC Container, or any other method.
                    // Return QueryResult object containing IEnumerable<YouModelItem>

                    var options = context.QueryOptions;
                    var result  = new QueryResult <UserProfileModelObject>();
                    var query   = BusinessItemsLists.GetUsers();
                    if (!String.IsNullOrWhiteSpace(options.SortColumnName))
                    {
                        switch (options.SortColumnName.ToLower())
                        {
                        case "firstname":
                            if (options.SortDirection == SortDirection.Asc ||
                                options.SortDirection == SortDirection.Unspecified)
                            {
                                query = query.OrderBy(p => p.FirstName).ToList();
                            }
                            else
                            {
                                query = query.OrderByDescending(p => p.FirstName).ToList();
                            }

                            break;

                        case "lastname":
                            //query = query.OrderBy(p => p.LastName, options.SortDirection);
                            break;
                        }
                    }

                    string globalSearch = options.GetAdditionalQueryOptionString("Search");
                    if (null != globalSearch)
                    {
                        query = query.Where(i =>
                                            i.FirstName.ToLower().Contains(globalSearch.ToLower()) ||
                                            i.LastName.ToLower().Contains(globalSearch.ToLower()) ||
                                            i.User.UserName.ToLower().Contains(globalSearch.ToLower()) ||
                                            i.ContactEmail.ToLower().Contains(globalSearch.ToLower())
                                            ).ToList();
                    }

                    result.TotalRecords = query.Count();

                    if (options.GetLimitOffset().HasValue)
                    {
                        query = query
                                .Skip(options.GetLimitOffset().Value)
                                .Take(options.GetLimitRowcount().Value)
                                .ToList();
                    }

                    result.Items = query;

                    return(result);
                })
                                           );
            }

            return(View(model));
        }
Esempio n. 4
0
 public JsonResult Get()
 {
     return(Json(BusinessItemsLists.GetUsers().ToArray(), JsonRequestBehavior.AllowGet));
 }