我有一个存储库类,其中包含一个列表,其中包含填写表单的人员列表,如果他们将出席我的派对。 我读与GetAllRespones价值观和我添加值与AddResponse名单(通过接口)在c#中更新列表#
现在我要检查是否有人已经填充了我的形式,如果是我要检查,如果WillAttend的值更改并更新它。
我可以看到我做了什么下面这里
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PartyInvites.Abstract;
namespace PartyInvites.Models
{
public class GuestResponseRepository : IRepository
{
private static List<GuestResponse> responses = new List<GuestResponse>();
IEnumerable<GuestResponse> IRepository.GetAllResponses()
{
return responses;
}
bool IRepository.AddResponse(GuestResponse response)
{
bool exists = responses.Any(x => x.Email == response.Email);
bool existsWillAttend = responses.Any(x => x.WillAttend == response.WillAttend);
if (exists == true)
{
if (existsWillAttend == true)
{
return false;
}
var attend = responses.Any(x => x.Email == response.Email && x.WillAttend == response.WillAttend);
attend.WillAttend = response.WillAttend;
return true;
}
responses.Add(response);
return true;
}
}
}
的问题是,我在“attend.WillAttend”
错误是得到一个错误信息:BOOL不包含定义WillAttend并具有 没有扩展方法“WillAttend”接受 bool类型的第一个参数可以发现
任何人都可以帮我解决我的代码? :)
谢谢你的快速回复!实现了你建议的代码,但由于某种原因,var参数一直为空。有关于此的任何想法? – valheru
@valheru,你有'NullReferenceException'或看到使用调试器的值? –
按照TamásSzabó的建议,用x.WillAttend!= response.WillAttend修复它,现在它工作正常。非常感谢您的帮助! – valheru