/*Class definition*/
public class ConcreteClassModel : BaseModel
{
...
public bool IntersectsWith(ConcreteClassModel ccm)
{
ccm.StartDateDT = DateTime.Parse(ccm.StartDate);
ccm.EndDateDT = DateTime.Parse(ccm.EndDate);
this.StartDateDT = DateTime.Parse(this.StartDate);
this.EndDateDT = DateTime.Parse(this.EndDate);
return !(this.StartDateDT > ccm.EndDateDT || this.EndDateDT < ccm.StartDateDT);
}
}
/*Inside Controller Method*/
List<ConcreteClassModel> periods = LoadAllByParameters<ConcreteClassModel>(
ccm.CoverId, x => x.CoverId,
ccm.SectionId, x => x.SectionId);
var intersectingPeriods =
periods.Where(x => x.IntersectsWith(ccm));
StringBuilder partReply = intersectingPeriods.Aggregate(new StringBuilder(), (a, b) => a.Append(b));
********if (!partReply.ToString().IsNullOrEmpty())***************************
{
string reply =
"<div id='duplicateErrorDialog' title='Duplication Error'><span> Duplicate Period(s)</br>" +
partReply + "</span></ div >";
return Json(reply, JsonRequestBehavior.AllowGet);
}
return Json(null, JsonRequestBehavior.AllowGet);
似乎很好地工作,如果沒有重複的日期時間被發現空性反應會觸發我的JavaScript保存。但是可以使用: if(!partReply.ToString()。IsNullOrEmpty()) 由於StringBuilder沒有自己的.IsNullOrEmpty()等價物嗎? 我能找到的每條評論,問題等都與Strings相關,並且無法在MSDN上看到任何內容!我可以一個StringBuilder對象上使用的ToString()。IsNullOrEmpty()以上
那會更可靠? @DrewKennedy –