[C#] 纯文本查看 复制代码 namespace CiWong.YiShang.Repositories
{
internal class ShopmessageRepository : RepositoryBase
{
/// <summary>
/// 根据页面输入的团队Id来获取当前id已经提交的消息个数
/// </summary>
/// <param name="SendUserId">团队Id</param>
/// <returns>如果消息个数大于0,则提示“已申请,不能重复申请”</returns>
public int GetCount(int sendUserId,int recvId,int type) {
var strSql = new StringBuilder();
strSql.Append("select count(*) from shopmessagedetails where SendUserId=@SendUserId and RecvUserId=@RecvUserId and
MessageType=@Type ");
MySqlParameter[] parameters = {
new MySqlParameter("@SendUserId", sendUserId),
new MySqlParameter("@RecvUserId", recvId),
new MySqlParameter("@Type",type)
};
return Convert.ToInt32(MySqlHelper.ExecuteScalar(ReadConnectionString,strSql.ToString(),parameters));
}
}
}
这个方法只能在当前的程序集内部调用,[C#] 纯文本查看 复制代码
namespace CiWong.YiShang.Services
{
public class ShopmessageService
{
/// <summary>
/// 构造函数
/// </summary>
public ShopmessageService()
{
_shopmessage = new ShopmessageRepository();
}
/// <summary>
/// 获取已提交的消息个数
/// </summary>
/// <param name="sendId">团队ID</param>
/// <returns></returns>
public int GetCountSubmited(int sendId,int recvId,int type) {
return _shopmessage.GetCount(sendId,recvId,type);
}
}[mw_shl_code=csharp,true]namespace CiWong.YiShang.Web.Areas.Admin.Controllers
{
/// <summary>
/// 教师中心
/// </summary>
[SelfOnly]
public class TeacherCenterController : Controller
{
/// <summary>
/// 获取已提交的消息个数
/// </summary>
/// <param name="sendId">团队Id</param>
/// <returns></returns>
public JsonResult GetCountSubmited(int sendId,int recvId,int type)
{
var rusult = _shopmessageService.GetCountSubmited(sendId,recvId,type);
return Json(rusult, JsonRequestBehavior.AllowGet);
}
//**********************************************
//问题就出在这,这里返回的是JsonResult,而GetCountSubmited(sendId,recvId,type)返回的是int,照原正常的逻辑是
//if(rusult>0) return 0;//如果rusult>0,则提示“已申请加入该团队,不能重复申请!”,
//else return 1;//rusult=0或-1时,则调用提交申请的方法
//或者将GetCountSubmited(sendId,recvId,type)这个方法放到ApplyJoinWorkroom这个方法中,试了好半天,不知道该怎么处理
/// <summary>
/// 提交申请
/// </summary>
/// <returns></returns>
[HttpPost]
public JsonResult ApplyJoin(User user, string bankName, string bankNo, string idCard, string lisence)
{
//var countApply = _shopmessageService.GetCountSubmited(sendId, user.UserID, type);
var result = _teacherService.Application(bankName, bankNo, idCard, lisence, user.UserID, user.UserName);
return Json(result.Entity, JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 申请加入制作团队
/// </summary>
/// <returns></returns>
public JsonResult ApplyJoinWorkroom(User user, int workroomId, string email, int period,string periodName, int subject,
string subjectName, string tel)
{
var arg = new TeamMemberMessageCommandArg
{
Email = email,
Period = period,
PeriodName = periodName,
Subject = subject,
SubjectName = subjectName,
Tel = tel
};
var result=_shopmessageService.Create(user.UserID, user.UserName, workroomId, "", 2, arg);
return Json(result > 0 ? 0 : -1);
}
}
}}
这个方法可供外部调用
[JavaScript] 纯文本查看 复制代码 //code[jquery]
<script type="text/javascript">
var userId = '@User.UserID';
#("$Btn_Submit").click( function () {
var _self = this;
var postdata = {};
postdata.workroomid = _self.WorkroomId.val();
//邮箱reg
var regex1 = new RegExp('^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@("@")([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$');
//电话reg
var regex2 = /^1[3|5|8][0-9]\d{4,8}$/;
if (!/^\d+$/.test(postdata.workroomid)) {
dlg.Msg.Err("团队ID不正确,请重新输入!");
//alert(postdata.workroomid);
return;
}
if (postdata.workroomid != "") {
$("#roomspan").hide();
}
postdata.email = _self.Email.val();
if (postdata.email != "") {
//dlg.Msg.Err("请填写E-mail");
$("#emailspan").hide();
};
if (!postdata.email.match(regex1)) {
dlg.Msg.Err("邮箱格式不正确,请重新输入!");
$("#E-mail").focus();
return;
}
postdata.period = _self.Period.val();
postdata.periodname = _self.Period.find("option:selected").text();
postdata.subject = _self.Subject.val();
postdata.subjectname = _self.Subject.find("option:selected").text();
postdata.tel = _self.Tel.val();
if (postdata.tel != "") {
//dlg.Msg.Err("请填写联系电话");
$("#telspan").hide();
};
if (!postdata.tel.match(regex2)) {
dlg.Msg.Err("电话格式不正确,请重新输入!");
$("#Tel").focus();
return;
}
//跟着感觉走的话,方法应该放到这个post里面才对,但我不知该怎么综合上面两个方法,不可能post里面再放个post吧?
$.post("/admin/teachercenter/applyjoinworkroom", postdata, function (ret) {
if (ret == 0) {
dlg.Msg.Cor("申请成功!");
} else if (ret == 1) {
dlg.Msg.Cor("已经提交申请!");
} else {
dlg.Msg.Err("申请失败!");
}
});
}
)
</script> [/mw_shl_code]
页面html:[HTML] 纯文本查看 复制代码 <!-- 我加入的制作团队 -->
<div id="myjoin" class="tabCon">
<table class="com-tb mt20">
<colgroup>
<col>
<col class="wp10">
<col class="wp10">
<col class="wp10">
<col class="wp15">
<col class="wp20">
</colgroup>
<tr>
<th>团队名称</th>
<th>ID</th>
<th>负责人</th>
<th>联系方式</th>
<th>所在区域</th>
<th>操作</th>
</tr>
</table>
<h2 class="colT ht mt30">我要加入团队</h2>
<ul class="rel-team" id="applyjoin">
<li>
<dl class="optBox">
<dt class="opt">
<label for="">团队ID:</label></dt>
<dd class="opCon">
<input type="text" name="workroomid" class="txt" id="workroomid" onblur="RegSendId()">
<span id="roomspan" class="opspan">* 团队Id不能为空</span></dd>
</dl>
</li>
<li>
<dl class="optBox">
<dt class="opt">
<label for="">姓 名:</label></dt>
<dd class="opCon">
@User.UserName
</dd>
</dl>
</li>
<li>
<dl class="optBox">
<dt class="opt">
<label for="">E-mail :</label></dt>
<dd class="opCon">
<input id="E-mail" type="text" name="email" class="txt">
<span id="emailspan" class="opspan">* E-mail不能为空</span></dd>
</dl>
</li>
<li>
<dl class="optBox">
<dt class="opt">
<label for="">所教学段:</label></dt>
<dd class="opCon">
<select class="mt5 wp20" name="period">
</select>
</dd>
</dl>
</li>
<li>
<dl class="optBox">
<dt class="opt">
<label for="">所教科目:</label></dt>
<dd class="opCon">
<select class="mt5 wp20" name="subject">
</select>
</dd>
</dl>
</li>
<li>
<dl class="optBox">
<dt class="opt">
<label for="">联系电话:</label></dt>
<dd class="opCon">
<input id="Tel" type="text" name="tel" class="txt">
<span id="telspan" class="opspan">* 联系电话不能为空</span></dd>
</dl>
</li>
</ul>
<p class="mt30"><a id="Btn_Submit" href="javascript:;" class="subBtn">提交申请</a></p>
</div>
站长,帮忙看下,这个折腾了我一下午,应该是很多基础性的东西没掌握好,站长多指点指点
还有MVC中Control中方法的返回值类型为ActionResult是对应View中的视图,但返回值为JsonResult是什么作用?序列化吗?
如果返回值类型是JsonResult,那么怎么才能看到是否调用到了数据,比如:
我的那个方法:
$("#Btn_Submit").click( function () {
var postdata = {};
postdata.sendId=$("name").val();//团队id
postdata.recvId=@User.userid;
postdata.type=1;
$.post("/admin/teachercenter/GetCountSubmited",postdata,function(ret){
if(ret>0){
//alert(data);//这里本来想做一下测试,用firebug调试试了半天,问题是程序都没走进来,所以请教飞哥,像JsonResult这种返回值在
//jquery中怎么来测试是否查询到了数据,实力n多个方式,就是不弹框,我郁闷了。。。
alert("已申请加入该团队,不能重复申请!");
}
alert("申请成功!");
}
} |