public bool CanSave(object param) { var checkmaster = MasterList.Where(x => x.IsCheckedMaster == true).ToList(); var check = TransactionList.Where(x => x.IsChecked == true).ToList(); string date = this.DateFormat as string; int count = 0; if (check != null && check.Count != 0) { foreach (var item in check) { try { if (!string.IsNullOrEmpty(item.StartDate) && !string.IsNullOrWhiteSpace(item.StartDate) && !string.IsNullOrEmpty(item.EndDate) && !string.IsNullOrEmpty(item.EndDate)) { //item.StartDate = item.StartDate.Replace('.', '/'); //item.StartDate = item.StartDate.Replace('-', '/'); //item.EndDate = item.EndDate.Replace('.', '/'); //item.EndDate = item.EndDate.Replace('-', '/'); var Start = (DateTime.ParseExact(item.StartDate, date, CultureInfo.InvariantCulture)); var End = (DateTime.ParseExact(item.EndDate, date, CultureInfo.InvariantCulture)); this.DateErrors = ""; if (End > Start) { count++; } else { this.DateErrors = "End Date should be greater than start date!"; return(false); } } } catch (Exception ex) { this.DateErrors = "Please enter the date in " + date + " format!"; return(false); } } var checkedcount = check.Count(); if (checkedcount == count && checkedcount > 0) { return(true); } else { return(false); } } else if (checkmaster != null) { var checkedcount = checkmaster.Count(); if (checkedcount > 0) { return(true); } else { return(false); } } else { return(false); } }