处理传参和底层方法的实现()

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
using Cn.Com.Farm.Common;
using Cn.Com.Farm.DAL;
using Cn.Com.Farm.Model;
using System.Linq.Expressions;
using Cn.Com.Farm.Model.Entity;
namespace Cn.Com.Farm.BLL
{
    /// <summary>
    /// 自己新建 空间好友表
    /// </summary>
    public partial class SpaceFriendBLL : BaseBLL, IDisposable
    {
        public IEnumerable<SpaceFriend> GetSelSpaceFriends(string id, string did, string keyword)  //, string keyword
        {
            using (SpaceFriendBLL bll = new SpaceFriendBLL())
            {
                var queryData = bll.FindALL();
                   UserInfo us = new UserInfo();
                ////  var queryData;
                if (!String.IsNullOrWhiteSpace(did))
                {
                    if (!String.IsNullOrWhiteSpace(keyword))
                    {
                     
                        using (var userbll = new UserInfoBLL())
                        {
                            us=userbll.Fetch(x => x.FName.Contains(keyword));
                        }
                        queryData = queryData.Where(x => x.FUserId == id && x.FState == 1 && x.FIsDelete == false && x.FTeamId == did && x.FFriendId == us.FId);  // && x.FFriendName.Contains(keyword)
                    }
                    else
                    { 
                      queryData = queryData.Where(x => x.FUserId == id && x.FState == 1 && x.FIsDelete == false && x.FTeamId == did);
                    }

                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(keyword))
                    {
                      
                        using (var userbll = new UserInfoBLL())
                        {
                            us=userbll.Fetch(x => x.FName.Contains(keyword));
                        }
                        queryData = queryData.Where(x => x.FUserId == id && x.FState == 1 && x.FIsDelete == false && x.FFriendId == us.FId);  // && x.FFriendName.Contains(keyword)
                    }
                    else
                    {
                        queryData = queryData.Where(x => x.FUserId == id && x.FState == 1 && x.FIsDelete == false);
                    }
                  

                }


              // var  queryData= bll.FindALL().Where(x => x.FUserId == id && x.FState == 1 && x.FIsDelete == false&&x.FTeamId == did );// && x.FFriendName.Contains(keyword)
                using (UserInfoBLL userbll = new UserInfoBLL())
                {
                    using (SpaceTeamBLL teambll = new SpaceTeamBLL())
                    {
                        var result = (from c in queryData.ToList()
                                      join pro in userbll.FindALL().ToList() on c.FFriendId equals pro.FId
                                      join team in teambll.FindALL().Where(x => x.FUserId == id) on c.FTeamId equals team.FId into S
                                      from t in S.DefaultIfEmpty()
                                      select new SpaceFriend
                                      {
                                          FId = c.FId,//好友列表编号 
                                          FUserId = c.FUserId,//本人编号
                                          FFriendId = c.FFriendId,//好友编号
                                          FFriendName = pro.FName,
                                          FTeamId = t == null ? "" : t.FName,
                                          FCreatorId = c.FCreatorId,//创建人
                                          FCreateTime = c.FCreateTime,//创建时间
                                          FUpdatorId = c.FUpdatorId,//修改人
                                          FUpdateTime = c.FUpdateTime,//修改时间
                                          FDeleteId = c.FDeleteId,//删除人
                                          FDeleteTime = c.FDeleteTime,//删除时间
                                          FIsDelete = c.FIsDelete,//删除状态
                                          FState = c.FState,//好友状态
                                          FType = c.FType,
                                          FRemarks = c.FRemarks//备注
                                      });
                        return result;
                    }
                }
            }
        }

    }
}

以上是好友分类的一个底层BLL的相关代码:(他将一些逻辑方面的操作放到此处进行处理)

SpaceFriendController控制器里有对自己定义BLL的调用:

      [HttpGet]
        [SupportFilter(FCode = "PersonalSpace_SpaceFriend_List")]//判断页面是否有权限,FCode 调用枚举,没有的自己补,格式为:Areas_Controller_Action,例如:Heart_AgrBaseArea_Add
        public ActionResult List(string cid, string keyword, int page = 1, int pageSize = 20) //, string keyword
        {
            IsAuthorityButton("PersonalSpace_SpaceFriend_List");
            IDictionary<string, object> dic = new Dictionary<string, object>();


            //var pageList = list.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            //var pageList2 = new PagedList<UserFavorite>(pageList, page, pageSize, pageList.Count());

            var result = bll.GetSelSpaceFriends(CurrentUser.FId, cid, keyword).AsQueryable<SpaceFriend>().ToPagedList(page, 10);//, keyword
          //  ViewBag.did = did;
            using (SpaceTeamBLL teambll = new SpaceTeamBLL())
            {
                dic.Add("list", result);
                using (SpaceTeamBLL teambl = new SpaceTeamBLL())
                {
                    IQueryable<SpaceTeam> team = teambll.FindALL().Where(x => x.FUserId == CurrentUser.FId);
                    dic.Add("spaceteam", team);
                }
                return PartialView(dic);// View(dic);
            }
        }

前台页面传参操作:(FSoSo.cshtml)

@model IList<SpaceTeam>
@{
    ViewBag.Title = "分类查询+搜索视图";
    string typeTopic = ViewBag.type;
   // string did = ViewBag.did;
    if (string.IsNullOrEmpty(typeTopic))
    {
        typeTopic = "1";
    }
    int type = int.Parse(typeTopic);
    string TopPicId = ViewBag.TopPicId;
    string RelativeUrl = ViewBag.RelativeUrl;
    string to = "";
    if (!string.IsNullOrWhiteSpace(Request["cid"]))
    {
        to = Request["cid"];
    }
    string toYn = "";
    if (!string.IsNullOrWhiteSpace(Request["yn"]))
    {
        toYn = Request["yn"];
    }
}



   <script src="/js/jquery-1.7.1.js"></script>
<script src="/res/dialog/lhgdialog.js"></script>

    <script src="/js/jquery.unobtrusive-ajax.js"></script>
<script src="/js/jquery.validate.js"></script>
<script src="/js/jquery.validate.unobtrusive.js"></script>

    <link href="/css/init.css" rel="stylesheet"/>
<link href="/css/css/head_style.css" rel="stylesheet"/>
<link href="/css/css/copyright.css" rel="stylesheet"/>
<link href="/css/css/tree_style.css" rel="stylesheet"/>
<link href="/css/css/style.css" rel="stylesheet"/>

    <link href="/css/page.css" rel="stylesheet"/>

    <link href="/css/personalSpace/style.css" rel="stylesheet"/>

    <script src="/res/jquery-ui/js/jquery-ui-1.10.1.custom.js"></script>
<script src="/res/jquery-ui/locale/jqueryui.datapicker.zh-cn.js"></script>

    <link href="/res/jquery-ui/css/south-street/jquery-ui-1.10.3.custom.css" rel="stylesheet"/>
    
    <script type="text/javascript">
        function SearchChanged(e) {
            window.location = '@RelativeUrl/?type=@(type)&cid=@(Request["cid"])&yn=@(Request["yn"])' +
                        '&keyword=' + e.value + '&order=@Request["order"]' + '&did=@Request["did"]' + '&view=@Request["view"]';
        }

        function PriorYear() {
            $('.year').html(Number($('.year').html()) - 1);
            RefreshMonth();
        }

        function NextYear() {
            $('.year').html(Number($('.year').html()) + 1);
            RefreshMonth();
        }

        function RefreshMonth() {
            var year = Number($('.year').html());
            var param = { type: '1', cid: '', keyword: '', year: '' };
            param.type = '@type';
            param.cid = '@to';
            param.keyword = '@Request["keyword"]';
            param.year = year;
            var order = '@Request["order"]';
            var viewMode = '@Request["view"]';
            $.ajax({
                type: "post",
                url: "/Personal/Space/Calendar/Stat",
                dataType: "json",
                data: param,
                success: function (data) {
                    $("li span.c_tx2").each(function (index1, s) {
                        $(s).html(((index1 + 1) > 12 ? (index1 + 1 - 12) : (index1 + 1)) + "");
                        $(s).attr("title", "0篇文章");
                    });
                    $(data).each(function (index, e) {
                        $("li span.c_tx2").each(function (index1, s) {
                            var cm = ((index1 + 1) > 12 ? (index1 + 1 - 12) : (index1 + 1));
                            if (e.month == cm) {
                                $(s).attr("title", e.count + "篇文章");
                                var sm = e.month.toString();
                                if (sm.length < 2) sm = "0" + sm;
                                $(s).html("<a href='@RelativeUrl/?type=@(type)&cid=" + param.cid + "&yn=" + year.toString() + sm +
                        "&keyword=" + param.keyword + "&order=" + order + "&view=" + viewMode +
                        "' style='vertical-align:middle'>" + e.month + "月</a>");
                                if (year.toString() + sm == "@(toYn)") {
                                    $(s).css("background", "#39f");
                                    $(s).html("<a href='@RelativeUrl/?type=@(type)&cid=" + param.cid + "&yn=" + year.toString() + sm +
                        "&keyword=" + param.keyword + "&order=" + order + "&view=" + viewMode +
                        "' style='vertical-align:middle; color:#fff;'>" + e.month + "月</a>");
                                }
                            }
                        });
                    });
                }
            });
        }

        $(function () {
            RefreshMonth();
        });
</script>
    <div class="clearfloat">
</div>
<div class="container">
    <div class="menuTitle">
        搜索好友
    </div>
    <div class="menuContent">
        <div style="border: 1px solid green; vertical-align: middle;  190px; height: 20px;
            padding-left: 5px">
            <input type="text" id="txtSearch" style="155px"  value="@Request["keyword"]" 
            onchange="SearchChanged(this)"/>
            <a class="icon_search" href="javascript:;"></a>
        </div>
    </div>
</div>

<!--获取用户分类开始-->
<div class="container">
    @{ 
        string fuid = LoginBLL.GetCurrentUserFid();
        SpaceTeamBLL bll = new SpaceTeamBLL();
        var toplist = bll.FindALL().Where(x => x.FUserId == fuid).ToList();

        //var toplist = Model;
        var top1 = toplist.Where(x => x.FUserId == fuid).Where(s=>s.FParent==null).ToList();
        foreach (var top1item in top1)
        {
        <div class="menuTitle">
          @top1item.FName
        </div>
        <div class="menuContent">
            <ul>
                @{
                    <li  
                    @if (top1item.FId == to)
                    {
                        <text>style="  background:#39f;"</text>
                    }
                    ><a 
                    @if (top1item.FId == to)
                    {
                        <text>style="  color:#fff;"</text>
                    }
                     href = "@RelativeUrl/?type=@(type)&cid=@(top1item.FId)&yn=@(Request["yn"])
                     @if (!string.IsNullOrWhiteSpace(Request["keyword"]))
                     {
                        <text>&keyword=@Request["keyword"]</text>
                     }
                     @if (!string.IsNullOrWhiteSpace(Request["order"]))
                     {<text>&order=@Request["order"]</text>}
                     @if (!string.IsNullOrWhiteSpace(Request["view"]))
                     {
                        <text>&view=@Request["view"]</text>   
                     }">全部</a></li>
                }
                @{
                     var top2 = toplist.Where(x => x.FParentId == top1item.FId).ToList();
                     foreach (var top2item in top2)
                     {
                    <li  
                    @if (top2item.FId == to)
                    {
                        <text>style="  background:#39f;"</text>
                    }
                    ><a 
                    @if (top2item.FId == to)
                    {
                        <text>style="  color:#fff;"</text>
                    }
                     href="@RelativeUrl/?type=@(type)&cid=@(top2item.FId)&yn=@(Request["yn"])
                     @if (!string.IsNullOrWhiteSpace(Request["keyword"]))
                     {
                        <text>&keyword=@Request["keyword"]</text>
                     }
                     @if (!string.IsNullOrWhiteSpace(Request["order"]))
                     {<text>&order=@Request["order"]</text>}
                     @if (!string.IsNullOrWhiteSpace(Request["view"]))
                     {
                        <text>&view=@Request["view"]</text>   
                     }">@top2item.FName</a></li>
                     }}
            </ul>
        </div>
        <div class="clearfloat">
        </div>
        }
    }
</div>
有些梦想是遥不可及的,除非你坚持!
原文地址:https://www.cnblogs.com/softmans/p/3267253.html