コード例 #1
0
        // GET: Members/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Member member2 = db.Members.Find(id);

            if (member2 == null)
            {
                return(HttpNotFound());
            }
            MemberTaskView result = new MemberTaskView();

            result.singleMember = member2;
            result.memberTask   = db.MemberTasks.Where(i => i.MemberId == id).ToList();

            return(View(result));
            //return View(member);
        }
コード例 #2
0
        // GET: Members
        public ActionResult Index(int?id, string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort       = sortOrder;
            ViewBag.NameSortParm      = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.CommunitySortParm = sortOrder == "Community" ? "community_desc" : "Community";
            ViewBag.EmailSortParm     = sortOrder == "Email" ? "email_desc" : "Email";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;
            var members = db.Members.Include(m => m.Community);

            if (!String.IsNullOrEmpty(searchString))
            {
                members = members.Where(m => m.LastName.ToUpper().Contains(searchString.ToUpper()) || m.Phone.ToString().ToUpper().Contains(searchString.ToUpper()) || m.Email.ToUpper().Contains(searchString.ToUpper()) || m.Community.Name.ToUpper().Contains(searchString.ToUpper()) || m.FirstName.ToUpper().Contains(searchString.ToUpper()));
            }
            switch (sortOrder)
            {
            case "name_desc":
                members = members.OrderByDescending(m => m.LastName);
                break;

            case "Community":
                members = members.OrderBy(m => m.Community.Name);
                break;

            case "community_desc":
                members = members.OrderByDescending(m => m.Community.Name);
                break;

            case "Email":
                members = members.OrderBy(m => m.Email);
                break;

            case "email_desc":
                members = members.OrderByDescending(m => m.Email);
                break;

            default:
                members = members.OrderBy(m => m.LastName);
                break;
            }

            int            pageSize   = 3;
            int            pageNumber = (page ?? 1);
            MemberTaskView result     = new MemberTaskView();

            //result.member = db.Members.Include(c => c.Community).ToList();
            if (id != null)
            {
                result.member = members.Where(i => i.CommunityId == id).ToList();
            }
            else
            {
                result.member = members.ToList();
            }


            result.memberTask  = db.MemberTasks.ToList();
            result.pagedMember = members.ToPagedList(pageNumber, pageSize);
            return(View(result));
        }