public virtual async Task <bool> DeleteClientAsync() { var shouldDelete = await this._dialogService.ShowDialogYesNo(Resources.Dialog_Title_Attention, Resources.Dialog_Question_DeleteClient); if (!shouldDelete) { return(false); } try { CityToPostalCode oldCityToPostalCode = this._currentClient.CityToPostalCode; this._repository.Delete(this._currentClient); this.DeletePostalCodeIfNecessary(oldCityToPostalCode); this.SendRemoveClientMessage(); return(true); } catch (Exception e) { await this._dialogService.ShowMessage(Resources.Dialog_Title_CanNotDeleteClient, e.Message); return(false); } }
private static bool AreEqualCityToPostalCodes(CityToPostalCode cityToPostalCode1, CityToPostalCode cityToPostalCode2) { if (cityToPostalCode1.PostalCode == cityToPostalCode2.PostalCode && cityToPostalCode1.City == cityToPostalCode2.City) { return(true); } return(false); }
/// <summary> /// Deletes the previous postal code - city combination when no other client possesses it. /// </summary> /// <exception cref="Exception">Thrown when no database connection or postal code could not be deleted.</exception> private void DeletePostalCodeIfNecessary(CityToPostalCode cityToPostalCode) { if (cityToPostalCode == null || string.IsNullOrEmpty(cityToPostalCode.PostalCode)) { return; } Conjunction conjunction = Restrictions.Conjunction(); conjunction.Add(Restrictions.Where <Client>(c => c.CityToPostalCode.PostalCode == cityToPostalCode.PostalCode)); int references = this._repository.GetQuantityByCriteria <Client>(conjunction); if (references == 0) { this._repository.Delete(cityToPostalCode); } }
private void FillCity() { CityToPostalCode cityToPostalCode = null; try { cityToPostalCode = this._repository .GetByCriteria <CityToPostalCode>(Restrictions.Where <CityToPostalCode>(x => x.PostalCode == this.PostalCode), 1) .FirstOrDefault(); } catch { // do nothing } if (cityToPostalCode != null) { this.City = cityToPostalCode.City; } }