我有用于向他们发送邮件的用户列表。我想在另一个列表框中显示选定的用户。我怎样才能做到这一点?

时间:2018-09-20 06:32:49

标签: asp.net-mvc jqgrid

我有以下代码显示用户列表,当我选择用户并单击“发送”时,它将发送邮件。但是我想显示另一个列表,该列表将从选定的值中获取用户,然后发送邮件。

查看代码:

<div class="modal fade small" id="invitiesModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h5 class="modal-title" id="myModalLabel">Share</h5>
                </div>
                <div class="modal-body">

                    <table id="tblMeeting">  </table>
                    <div id="pager"></div>
                </div>

                <input type="hidden" value="0" id='meetingId' name='meetingId'>

                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="btnShareMOM" data-dismiss="modal">Send Mail</button>
                </div>
            </div>
        </div>
    </div>

JQGrid:

var idsOfSelectedRows = new Array();

$("#DraftFile").change(function () {
    if (window.File && window.FileReader && window.FileList && window.Blob) {
        document.getElementById("mom_btn1").style.display = "inline-block";
        document.getElementById("mom_btn2").style.display = "inline-block";
    }
});

checkName = function (value) {
    //debugger;

    if (value.length == 0) {
        return [false, "Please enter the Name!"]
    }
    return [true];
};


function ShareMOM(meetingId) {

    var InvityIds = new Array();


    //alert(meetingId);
    $.ajax({
        url: '@Url.Action("ShareView", "PostMeetingDocument", new { area = "Postmeeting" })',
        type: "Get",
        async: false,
        data: { "meetingId": meetingId },
        cache: false,
        success: function (data) {
            InvityIds = data;
            //console.log(data);
        },
        error: function () {
            //alert('oops something wrong!!');
        }
    })

    idsOfSelectedRows = new Array();

    //$.each(InvityIds, function (index, val) {
    //    idsOfSelectedRows.push(val);
    //});

    var updateIdsOfSelectedRows = function (id, isSelected) {
        var contains = idsOfSelectedRows.indexOf(id);
        if (!isSelected && contains>=0) {
            for (var i = 0; i < idsOfSelectedRows.length; i++) {
                if (idsOfSelectedRows[i] == id) {
                    idsOfSelectedRows.splice(i, 1);
                    break;
                }
            }
        }
        else if (contains<0) {
            idsOfSelectedRows.push(id);
        }
    };

    $("#tblMeeting").jqGrid("GridUnload")

    $("#meetingId").val(meetingId);

    $("#Invities").show();
    var URL = '@Url.Action("GetInvitees", "PostMeetingDocument", new { area = "Postmeeting", meetingId = "_MeetingId" })';
    URL = URL.replace("_MeetingId", meetingId);

    $('#tblMeeting').jqGrid({
        url: URL,
        datatype: "json",
        mytype: "GET",
        colNames: ["UserID", "FirstName","LastName"],
        colModel: [
            { name: 'UserID', index: 'UserID', width: 55, hidden: true, key: true, editable: false, checked: true },
            { name: 'FirstName', index: 'FirstName', sortable: false, align: "left", width: 150, editable: true, search: false, editrules: { custom: true, custom_func: checkName }, searchoptions: { sopt: ['cn'] } },
            { name: 'LastName', index: 'LastName', sortable: false, align: "left", width: 150, editable: true, search: false, editrules: { custom: true, custom_func: checkName } },
            //{ name: 'Department', index: 'Department', sortable: false, align: "left", width: 150, editable: true, search: false, editrules: { custom: true, custom_func: checkName } }
        ],
        rowNum: 30,
        rowList: [30, 60, 90],
        multiSort: true,
        sortname: 'FirstName asc,LastName',
        sortorder: 'asc',
        height: 350,
        pager: jQuery('#pager'),
        width: 510,// 450,
        multiselect: true,
        multiPageSelection: true,
        viewrecords: true,
        //caption: "Add Invities",
        onSelectRow: function (rowid, status) {
            //selected[rowid] = status;
            //setSelectedDeviceCount();
            updateIdsOfSelectedRows(rowid, status);
        },
        onSelectAll: function (aRowids, status) {
            var i, count, id;
            for (i = 0, count = aRowids.length; i < count; i++) {        
                //selected[rowids[i]] = status;
                id = aRowids[i];
                updateIdsOfSelectedRows(id, status);
            }
        },
        loadComplete: function () {
            $.each(idsOfSelectedRows, function (index, val) {
                //var ids = grid.jqGrid('getDataIDs');
                //for (var i = 0; i < ids.length; i++) {
                //    if (selected[ids[i]] === true) {
                //        grid.setSelection(ids[i], false);
                //    }
                //}
                $('#tblMeeting').jqGrid("setSelection", val, true);
            });
        },
        shrinkToFit: true
    }).navGrid(pager, { edit: false, add: false, del: false, search: false, refresh: true, addtext: "Share MOM", searchtext: "Search", refreshtext: "Refresh" },
    {
        //Edit.
    },
    {

        // add options.
    },
    {
        //Delete.
    }
    );
}


$("#btnShareMOM").on('click', function () {

    //var UserId = new Array();

    $.ajax({
        url: '@Url.Action("SendMomAll", "PostMeetingDocument", new { area = "Postmeeting" })',
        type: "Get",
        async: false,
        data: { "meetingId": $("#MeetingID").val(), "userId": idsOfSelectedRows.join() },
        cache: false,
        success: function (data) {
           // InvityIds = data;
            //console.log(data);
        },
        error: function () {
            //alert('oops something wrong!!');
        }
    })
});

控制器:

public ActionResult SendMomAll(int meetingId, string userId)
{
        var EmailTemplate = db.EmailTempletes.Where(l => l.Name == "FinalMOM").FirstOrDefault();

        List<int> userIds = Array.ConvertAll<string, int>(userId.Split(','), new Converter<string, int>(Convert.ToInt32)).ToList();

        List<string> UserMailList = (from u in db.VMUsers where userIds.Contains(u.UserID) select u.Email.Trim()).ToList();

        string UserMail = string.Join(",", UserMailList.ToArray());

        //var Note = db.Notes.OrderByDescending(l => l.NoteId).FirstOrDefault(l => (l.PreviousNoteId == (-1) || l.PreviousNoteId == (-2)) && (l.ParentNoteId == (-1) || l.ParentNoteId == (-2)) && l.MeetingId == meetingId);
        //var Note = db.Notes.OrderByDescending(l => l.NoteId).FirstOrDefault(l => l.MeetingId == meetingId);
        //var Document = db.Files.OrderByDescending(l => l.FileId).FirstOrDefault(l => l.NoteId == Note.NoteId);

        var strMappath = Server.MapPath("~/Repository/Meetings/" + meetingId.ToString() + "/");
        //strMappath += Document.FileName;

        var dir = new DirectoryInfo(strMappath).GetFiles("*.*").OrderByDescending(l=>l.LastWriteTime).FirstOrDefault();

        MailBox mailbox = new MailBox();
        mailbox.MailTo = UserMail;
        mailbox.Subject = EmailTemplate.Subject;
        mailbox.Body = EmailTemplate.TempleteBody;
        mailbox.IsAttachment = true;
        mailbox.AttachmentsPath = strMappath + dir.Name;
        mailbox.Status = false; 
        db.MailBox.Add(mailbox);
        db.SaveChanges();
        //return View("Index");
        return Json(mailbox,JsonRequestBehavior.AllowGet);
}

现在我要显示此列表中所选用户的列表

0 个答案:

没有答案