[DataContract]
public class ResultEntity<T>
{
/// <summary>
/// 返回码
/// </summary>
[DataMember]
public int ReturnCode { get; set; }
/// <summary>
/// 操作结果。
/// </summary>
[DataMember]
public virtual T Result { get; set; }
/// <summary>
/// 操作结果消息。
/// </summary>
[DataMember]
public string Message { get; set; }
/// <summary>
/// 操作出现错误的异常对象。
/// </summary>
[DataMember]
public Exception ErrorException { get; set; }
}
2.
/// </summary>
[DataContract]
public class GeneralResult : ResultEntity<bool>
{
/// <summary>
/// 操作结果编号。false表示失败,true表示成功。
/// </summary>
[DataMember]
public override bool Result
{
get { return base.Result; }
set { base.Result = value; }
}
public void SetErrorMessage(string message, int returnCode = 0, Exception ex = null)
{
Result = false;
Message = message;
ErrorException = ex;
ReturnCode = returnCode;
}
public void SetSuccessMessage(string message="")
{
Result = true;
Message = message;
}
}
// 同意互转
public ActionResult Accept(int relationRecordId)
{
GeneralResult result = _userRepostRelationService.Accept(UserId,relationRecordId);
return Json(result);
}
private bool ValidateCurrentRelation(int requestUserId, int receiveUserId, GeneralResult result)
{
UserRepostRelation repostRelation = _userRepostRelationRepository.GetRepostRelation(requestUserId,
receiveUserId);
if (repostRelation != null)
{
if (repostRelation.IsBuildRelation)
result.SetErrorMessage("已建立互转关系。");
else if (repostRelation.RequestUserId == requestUserId)
result.SetErrorMessage("你已向对方发送过互转申请");
else
result.SetErrorMessage("对方已向你发送了互转申请。");
return false;
}
return true;
}