//UdList Object Scope Validation validate entire object... private byte UdListItemIsValid(UdListItem udListItem, out string errorMessage) { //validate key errorMessage = ""; if (string.IsNullOrEmpty(udListItem.UdListItemID)) { errorMessage = "ID Is Required."; return(1); } var count = UdListList. Where(q => q.UdListID == udListItem.UdListID).Single(). UdListItems. Where(x => x.UdListItemID == udListItem.UdListItemID).Count(); if (count > 1) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(1); } if (UdListItemExists(udListItem.UdListID, udListItem.UdListItemID.ToString(), (int)udListItem.AutoID)) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(1); } //validate Description if (string.IsNullOrEmpty(udListItem.Description)) { errorMessage = "Description Is Required."; return(1); } return(0); }
public void DeleteUdListItemCommand() { int i = 0; //temp index int ii = 0; //calculated index for (int j = SelectedUdListItemList.Count - 1; j >= 0; j--) { UdListItem udListItem = (UdListItem)SelectedUdListItemList[j]; //get Max Index... i = SelectedUdList.UdListItems.IndexOf(udListItem); if (i > ii) { ii = i; } Delete(udListItem); UdListList.Where(q => q.AutoID == SelectedUdList.AutoID).FirstOrDefault().UdListItems.Remove(udListItem); } if (UdListList != null && SelectedUdList != null && SelectedUdList.UdListItems.Count > 0) { //back off one index from the max index... ii = ii - 1; //if they delete the first row... if (ii < 0) { ii = 0; } //need some work on this... //make sure it does not exceed the list count... if (ii >= SelectedUdList.UdListItems.Count) { ii = SelectedUdList.UdListItems.Count - 1; } //only allow commit for dirty validated records... SelectedUdListItem = SelectedUdList.UdListItems[ii]; if (Dirty) { AllowCommit = CommitIsAllowed(); } else { AllowCommit = false; } } else//only one record, deleting will result in no records... { SetAsEmptySelection(); } }
private bool NewUdListItem(string udListItemID) { UdListItem udListItem = new UdListItem(); _newUdListItemAutoId = _newUdListItemAutoId - 1; udListItem.AutoID = _newUdListItemAutoId; udListItem.UdListID = SelectedUdList.UdListID; udListItem.UdListItemID = udListItemID; udListItem.IsValid = 1; udListItem.NotValidMessage = "New Record Key Field/s Required."; udListItem.CompanyID = ClientSessionSingleton.Instance.CompanyID; UdListList.Where(q => q.AutoID == SelectedUdList.AutoID).FirstOrDefault().UdListItems.Add(udListItem); _serviceAgent.AddToUdListRepository(udListItem); SelectedUdListItem = SelectedUdList.UdListItems.LastOrDefault(); AllowEditUdListItem = true; return(true); }
//UdListItem Object.Property Scope Validation... private bool UdListItemIsValid(UdListItem udListItem, _udListItemValidationProperties validationProperties, out string errorMessage) { errorMessage = ""; switch (validationProperties) { case _udListItemValidationProperties.UdListItemID: //validate key if (string.IsNullOrEmpty(udListItem.UdListItemID)) { errorMessage = "ID Is Required."; return(false); } var count = UdListList. Where(q => q.UdListID == udListItem.UdListID).Single(). UdListItems. Where(x => x.UdListItemID == udListItem.UdListItemID).Count(); if (count > 1) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(false); } if (UdListItemExists(udListItem.UdListID, udListItem.UdListItemID.ToString(), (int)udListItem.AutoID)) { errorMessage = "UdListItem ID " + udListItem.UdListItemID + " Allready Exists..."; return(false); } break; case _udListItemValidationProperties.Description: //validate Description if (string.IsNullOrEmpty(udListItem.Description)) { errorMessage = "Description Is Required."; return(false); } break; } return(true); }
private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedUdList.UdListID)) { //check to see if key is part of the current udListlist... UdList query = UdListList.Where(udList => udList.UdListID == SelectedUdList.UdListID && udList.AutoID != SelectedUdList.AutoID).FirstOrDefault(); if (query != null) {//change to the newly selected udList... //before navigating to the newly selected client cached record revert the old one back to what it was... SelectedUdList.UdListID = SelectedUdListMirror.UdListID; SelectedUdList = query; return; } //it is not part of the existing list try to fetch it from the db... UdListList = GetUdListByID(SelectedUdList.UdListID, ClientSessionSingleton.Instance.CompanyID); if (UdListList.Count == 0) {//it was not found do new record required logic... NotifyNewRecordNeeded("Record " + SelectedUdList.UdListID + " Does Not Exist. Create A New Record?"); } else { SelectedUdList = UdListList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedUdList.UdListID != SelectedUdListMirror.UdListID) { SelectedUdList.UdListID = SelectedUdListMirror.UdListID; } } }