Ejemplo n.º 1
0
        public static SelectList GetSelectList_UserbyCreateModuel(object sValue, string ActionName, string ModuelName, string NullOrNameEmpty)
        {
            var                    selectListItems        = new List <SelectListItem>();
            UserRepository         userRepository         = new UserRepository(new Domain.ErpDbContext());
            UserTypePageRepository userTypePageRepository = new UserTypePageRepository(new Domain.ErpDbContext());
            PageRepository         pageRepository         = new PageRepository(new Domain.ErpDbContext());

            if (NullOrNameEmpty != null)
            {
                SelectListItem itemEmpty = new SelectListItem();
                itemEmpty.Text  = NullOrNameEmpty;
                itemEmpty.Value = null;
                selectListItems.Add(itemEmpty);
            }

            try
            {
                var page  = pageRepository.GetPageByAcctionController(ActionName, ModuelName);
                var utype = userTypePageRepository.GetAllItem().Where(x => x.PageId == page.Id);
                var model = utype.Select(x => new Areas.Administration.Models.UserTypePageViewModel
                {
                    PageId     = x.PageId,
                    UserTypeId = x.UserTypeId
                }).ToList();
                foreach (var i in model)
                {
                    var UserList = userRepository.GetUsers().Where(x => x.UserTypeId == i.UserTypeId)
                                   .Select(x => new SelectListItem
                    {
                        Value = x.Id.ToString(),
                        Text  = x.FullName
                    }).ToList();
                    selectListItems = selectListItems.Union(UserList).ToList();
                }
            }
            catch { }

            var selectList = new SelectList(selectListItems, "Value", "Text", sValue);

            return(selectList);
        }