private bool Validate(Constituent entity)
        {
            ValidationErrors.Clear();
            if (string.IsNullOrWhiteSpace(entity.Name)) ValidationErrors.Add(new KeyValuePair<string, string>("Name", "Name is required"));

            return ValidationErrors.Count == 0;
        }
        private bool ValidateSearch(Constituent entity)
        {
            ValidationErrors.Clear();

            if (entity.LookupId == null) ValidationErrors.Add(new KeyValuePair<string, string>("Supporter Id", "Supporter Id is required."));
            if (entity.Zipcode == null) ValidationErrors.Add(new KeyValuePair<string, string>("Zipcode", "Zipcode is required."));

            return ValidationErrors.Count == 0;
        }
        public Constituent Search(Constituent entity)
        {
            using (var db = new AppContext())
            {
                var ret = db.Constituents.Include(t => t.TaxItems).FirstOrDefault(c => c.LookupId == entity.LookupId && c.Zipcode.Substring(0, 5).Equals(entity.Zipcode.Substring(0, 5)));
                ValidateSearch(entity);
                if (ret == null) ValidationErrors.Add(new KeyValuePair<string, string>("Not Found", "No tax records found for given supporter."));

                return ret;
            }
        }
        public void Update(Constituent entity)
        {
            var isValid = Validate(entity);
            if (!isValid) return;

            using (var db = new AppContext())
            {
                var existing = db.Constituents.Find(entity.Id);
                if (entity.Equals(existing)) return;

                entity.IsUpdated = true;
                entity.UpdatedBy = "donor";
                db.Constituents.AddOrUpdate(entity);
                db.SaveChanges();
            }
        }
        //public override bool Equals(object obj)
        //{
        //    if (obj == null)
        //        return false;
        //    if (GetType() != obj.GetType()) return false;

        //    var constituent = (Constituent)obj;

        //    if (constituent.LookupId != LookupId) return false;
        //    if (!string.Equals(constituent.Name, Name, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Street, Street, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Street2, Street2, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.City, City, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.State, State, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Zipcode, Zipcode, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Email, Email, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    return constituent.Phone == Phone;
        //}

        protected bool Equals(Constituent other)
        {
            return(string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(LookupId, other.LookupId, StringComparison.OrdinalIgnoreCase) && string.Equals(FinderNumber, other.FinderNumber, StringComparison.OrdinalIgnoreCase) && string.Equals(Street, other.Street, StringComparison.OrdinalIgnoreCase) && string.Equals(Street2, other.Street2, StringComparison.OrdinalIgnoreCase) && string.Equals(City, other.City, StringComparison.OrdinalIgnoreCase) && string.Equals(State, other.State, StringComparison.OrdinalIgnoreCase) && string.Equals(Zipcode, other.Zipcode, StringComparison.OrdinalIgnoreCase) && string.Equals(Email, other.Email, StringComparison.OrdinalIgnoreCase) && string.Equals(Phone, other.Phone, StringComparison.OrdinalIgnoreCase));
        }
 public TaxViewModel()
 {
     Entity = new Constituent();
     SearchEntity = new Constituent();
     TaxItems = new List<TaxItem>();
     EventCommand = "Search";
     IsDetailsVisible = false;
     SelectedTaxYear = DateTime.Now.Year - 1;
     AcceptTerms = false;
 }
        //public override bool Equals(object obj)
        //{
        //    if (obj == null)
        //        return false;
        //    if (GetType() != obj.GetType()) return false;

        //    var constituent = (Constituent)obj;
            
        //    if (constituent.LookupId != LookupId) return false;
        //    if (!string.Equals(constituent.Name, Name, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Street, Street, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Street2, Street2, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.City, City, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.State, State, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Zipcode, Zipcode, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    if (!string.Equals(constituent.Email, Email, StringComparison.CurrentCultureIgnoreCase)) return false;
        //    return constituent.Phone == Phone;
        //}

        protected bool Equals(Constituent other)
        {
            return string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(LookupId, other.LookupId, StringComparison.OrdinalIgnoreCase) && string.Equals(FinderNumber, other.FinderNumber, StringComparison.OrdinalIgnoreCase) && string.Equals(Street, other.Street, StringComparison.OrdinalIgnoreCase) && string.Equals(Street2, other.Street2, StringComparison.OrdinalIgnoreCase) && string.Equals(City, other.City, StringComparison.OrdinalIgnoreCase) && string.Equals(State, other.State, StringComparison.OrdinalIgnoreCase) && string.Equals(Zipcode, other.Zipcode, StringComparison.OrdinalIgnoreCase) && string.Equals(Email, other.Email, StringComparison.OrdinalIgnoreCase) && string.Equals(Phone, other.Phone, StringComparison.OrdinalIgnoreCase);
        }