示例#1
0
        public UserViewModel GetByID(int ID)
        {
            UserViewModel hasil = new UserViewModel();

            hasil = (from User in db.User
                     join Role in db.Role
                     on User.RoleId equals Role.RoleID
                     join UserModify in db.User
                     on User.ModifyBy equals UserModify.UserId into GetUserModify
                     from gum in GetUserModify.DefaultIfEmpty()
                     join UserCreate in db.User
                     on User.CreatedBy equals UserCreate.UserId into GetUserCreate
                     from guc in GetUserCreate.DefaultIfEmpty()
                     where User.UserId == ID
                     select new UserViewModel
            {
                UserId = User.UserId,
                Name = User.Name,
                Address = User.Address,
                Phone = User.Phone,
                Email = User.Email,
                CreatedDate = User.CreatedDate,
                ModifyDate = User.ModifyDate,
                StringRole = Role.RoleName,
                GetUserModify = gum.Name,
                GetUserCreate = guc.Name,
                Status = User.Status,
                Password = User.Password
            }).FirstOrDefault();
            return(hasil);
        }
示例#2
0
        public UserViewModel GetUserAdmin()
        {
            var data = new UserViewModel();

            data.ListUser = (from User in db.User
                             join Role in db.Role
                             on User.RoleId equals Role.RoleID
                             join UserModify in db.User
                             on User.ModifyBy equals UserModify.UserId into GetUserModify
                             from gum in GetUserModify.DefaultIfEmpty()
                             join UserCreate in db.User
                             on User.CreatedBy equals UserCreate.UserId into GetUserCreate
                             from guc in GetUserCreate.DefaultIfEmpty()

                             where Role.RoleName == "Admin"
                             select new UserViewModel {
                UserId = User.UserId,
                Name = User.Name,
                Address = User.Address,
                Phone = User.Phone,
                Email = User.Email,
                UserName = User.UserName,
                Password = User.Password,
                CreatedDate = User.CreatedDate,
                CreatedBy = User.CreatedBy,
                ModifyDate = User.ModifyDate,
                ModifyBy = User.ModifyBy,
                RoleId = User.RoleId,
                Status = User.Status,
                StringRole = Role.RoleName,
                GetUserModify = gum.Name,
                GetUserCreate = guc.Name
            }).ToList();

            return(data);
        }