public void UpdateApplicationForEntry(ApplicationForEntry oldElement, ApplicationForEntry updatedApplicationForEntry) { oldElement.ApplicantId = updatedApplicationForEntry.ApplicantId; oldElement.ApplicantName = updatedApplicationForEntry.ApplicantName; oldElement.ApplicantSurname = updatedApplicationForEntry.ApplicantSurname; oldElement.ApplicantAge = updatedApplicationForEntry.ApplicantAge; oldElement.ApplicantHouse = updatedApplicationForEntry.ApplicantHouse; }
public ActionResult Post(ApplicationForEntry applicationForEntry) { bool isApplicantIdRepeating = true; var obj = this._applicationForEntryService.GetApplicationsForEntry().FirstOrDefault(x => x.ApplicantId == applicationForEntry.ApplicantId); if (obj == null) { isApplicantIdRepeating = false; } if ((!isApplicantIdRepeating) && (this._applicationForEntryService.ValidateRequestData(applicationForEntry))) { applicationForEntry.Id = this._applicationForEntryService.GetAutoincrementId(); this._applicationForEntryService.AddApplicationForEntry(applicationForEntry); return(Ok()); } else { return(UnprocessableEntity("Invalid request data")); } }
public ActionResult Put(int id, [FromBody] ApplicationForEntry applicationForEntry) { bool isApplicantIdRepeating = true; var obj = this._applicationForEntryService.GetApplicationsForEntry().FirstOrDefault(x => x.Id == id); if (obj == null) { return(NotFound()); } else if (this._applicationForEntryService.ValidateRequestData(applicationForEntry)) { var element = this._applicationForEntryService.GetApplicationsForEntry().FirstOrDefault(x => x.ApplicantId == applicationForEntry.ApplicantId); if (element == null) { isApplicantIdRepeating = false; } else if (element.Id == id) { isApplicantIdRepeating = false; } if (!isApplicantIdRepeating) { this._applicationForEntryService.UpdateApplicationForEntry(obj, applicationForEntry); return(Ok()); } else { return(UnprocessableEntity("Invalid request data")); } } else { return(UnprocessableEntity("Invalid request data")); } }
public bool ValidateRequestData(ApplicationForEntry applicationForEntry) { bool isTheApplicantValidName = false; bool isTheApplicantValidSurname = false; bool isTheApplicantValidAge = false; bool isTheApplicantValidId = false; bool houseWasFound = false; bool onlyLettersForName = false; bool onlyLettersForSurname = false; bool onlyNumbersForId = false; bool onlyNumbersForAge = false; int numOfDigitsForAge; int numOfDigitsForId; int posOfHouseInArray; numOfDigitsForAge = applicationForEntry.ApplicantAge.ToString().Length; numOfDigitsForId = applicationForEntry.ApplicantId.ToString().Length; posOfHouseInArray = Array.IndexOf(houses, applicationForEntry.ApplicantHouse.ToUpper()); if (applicationForEntry.ApplicantName.Length <= maxLengthForApplicantName) { isTheApplicantValidName = true; } if (applicationForEntry.ApplicantSurname.Length <= maxLengthForApplicantSurname) { isTheApplicantValidSurname = true; } if (numOfDigitsForAge <= maxNumOfDigitsForAge) { isTheApplicantValidAge = true; } if (numOfDigitsForId <= maxNumOfDigitsForId) { isTheApplicantValidId = true; } if (posOfHouseInArray > -1) { houseWasFound = true; } if (Regex.IsMatch(applicationForEntry.ApplicantName, @"^[a-zA-Z]+$")) { onlyLettersForName = true; } if (Regex.IsMatch(applicationForEntry.ApplicantSurname, @"^[a-zA-Z]+$")) { onlyLettersForSurname = true; } if (Regex.IsMatch(applicationForEntry.ApplicantId.ToString(), @"^[0-9]+$")) { onlyNumbersForId = true; } if (Regex.IsMatch(applicationForEntry.ApplicantAge.ToString(), @"^[0-9]+$")) { onlyNumbersForAge = true; } if ((isTheApplicantValidName) && (isTheApplicantValidSurname) && (isTheApplicantValidAge) && (isTheApplicantValidId) && (onlyLettersForName) && (onlyLettersForSurname) && (onlyNumbersForId) && (onlyNumbersForAge) && (houseWasFound)) { return(true); } else { return(false); } }
public void DeleteApplicationForEntry(ApplicationForEntry elementToRemove) { _applicationForEntryList.Remove(elementToRemove); }
public void AddApplicationForEntry(ApplicationForEntry applicationForEntry) { _applicationForEntryList.Add(applicationForEntry); }