public static int UpdatePersonAddress(int AddressId, PersonsAddressModel personAddress) => Update(PersonsAddressTable.TableName, new ParamtersMap { [PersonsAddressTable.PeAdStreetName] = personAddress.PeAdStreetName, [PersonsAddressTable.PeAdCity] = personAddress.PeAdCity, [PersonsAddressTable.PeAdPerIdFk] = personAddress.PeAdPerIdFk }, $"{PersonsAddressTable.PeAdId}={AddressId}");
public static int InsertPersonAddress(out long insertId, PersonsAddressModel personAddress) { var changedCount = Insert(out insertId, PersonsAddressTable.TableName, new ParamtersMap { [PersonsAddressTable.PeAdStreetName] = personAddress.PeAdStreetName, [PersonsAddressTable.PeAdCity] = personAddress.PeAdCity, [PersonsAddressTable.PeAdPerIdFk] = personAddress.PeAdPerIdFk }); return(changedCount); }
public void Edit(Window window) { IsInProgress = true; new Thread(() => { var peId = EditedPerson.PeId; EditedPerson = new PersonsModel() { PeId = peId, PeName = FullName, PeIdentity = PersonalId, PeType = (int)SelectedPersonType.CId, PeAddress = "" }; var personValueChange = DataAccess.UpdatePerson(EditedPerson.PeId, EditedPerson); if (personValueChange == 1) { var commChangeValue = DataAccess.DeletePersonCommunication(peId); foreach (var item in CommunicationSource) { item.CoPeIdFk = peId; var commValueChange = DataAccess.InsertPersonCommunication(out var id, item); AddedCommunication.Add(item); } var addressChangeValue = DataAccess.DeletePersonAddress(peId); var address = new PersonsAddressModel() { PeAdCity = City, PeAdStreetName = Adress, PeAdPerIdFk = EditedPerson.PeId }; DataAccess.InsertPersonAddress(out var adressId, address); AddedAddress.Add(address); } IsInProgress = false; App.Current.Dispatcher.Invoke((Action) delegate { window.DialogResult = true; window.Close(); }); }) { IsBackground = true }.Start();
public void Add(Window window) { IsInProgress = true; new Thread(() => { AddedPerson = new PersonsModel() { PeName = FullName, PeIdentity = PersonalId, PeType = (int)SelectedPersonType.CId, PeAddress = "" //PhoneNo = PhoneNo, //MobileNo = MobileNo, //Email = EmailAdress, //Address = "" }; var personValueChange = DataAccess.InsertPerson(out var personId, AddedPerson); AddedPerson.PeId = personId; foreach (var item in CommunicationSource) { item.CoPeIdFk = personId; var commValueChange = DataAccess.InsertPersonCommunication(out var id, item); AddedCommunication.Add(item); } var address = new PersonsAddressModel() { PeAdCity = City, PeAdStreetName = Adress, PeAdPerIdFk = AddedPerson.PeId }; DataAccess.InsertPersonAddress(out var adressId, address); AddedAddress.Add(address); IsInProgress = false; App.Current.Dispatcher.Invoke(() => { window.DialogResult = true; window.Close(); }); }) { IsBackground = true }.Start();
public void Done(object valuse) { var objs = valuse as object[]; Password = (objs[0] as PasswordBox).Password; ConfPass = (objs[1] as PasswordBox).Password; var window = objs[2] as Window; if (Password.Equals(ConfPass)) { IsInProgress = true; new Thread(() => { PersonsModel person = new PersonsModel() { PeId = Person.PeId, PeIdentity = PersonalId, PeName = FullName, PeType = (int)SelectedUserType.CId, PeAddress = "" }; var personChangeValue = 0; long personInsertId = 0; try { personChangeValue = DataAccess.UpdatePerson(Person.PeId, person); } catch { MessageBox.Show("could not open connection with server!\nCheck your internet connection or server is connected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } person.PeId = personInsertId; if (personChangeValue == 1) { UsersModel user = new UsersModel() { CreatedBy = SystemValues.LoginUser, UPIdFk = personInsertId, UEmail = EmailAdress, UUserName = Username, UPassword = Password.GetPasswordHashSHA256(), UIsActive = UserState.ToIntState(), UpdatedBy = SystemValues.LoginUser }; long userChangeValue = 0; try { userChangeValue = DataAccess.UpdateUser((int)person.PeId, user); } catch { MessageBox.Show("could not open connection with server!\nCheck your internet connection or server is connected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } if (userChangeValue == 1) { try { DataAccess.DeletePersonCommunication(person.PeId); } catch { MessageBox.Show("Filed to Edit user Communication, Address and Groups info"); return; } foreach (var item in CommunicationSource) { item.CoPeIdFk = person.PeId; try { var commValueChange = DataAccess.InsertPersonCommunication(out var id, item); AddedCommunication.Add(item); } catch { MessageBox.Show($"Could not Add {item.CoNameCfk} to this user", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } var address = new PersonsAddressModel() { PeAdCity = City, PeAdStreetName = Adress, PeAdPerIdFk = person.PeId }; try { DataAccess.DeletePersonAddress(person.PeId); } catch { MessageBox.Show("Filed to Edit user Address and Groups info"); return; } try { DataAccess.InsertPersonAddress(out var adressId, address); AddedAddress.Add(address); } catch { MessageBox.Show($"Could not Add Addess to this user", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } try { DataAccess.DeleteUserGroups((int)person.PeId); } catch { MessageBox.Show("Filed to Edit user Groups info"); return; } foreach (var item in AddedGroupsSource) { var userGroup = new UserGroupModel() { GroupId = item.GId, UserId = (int)person.PeId }; try { DataAccess.InsertUserGroups(out var n, userGroup); UserGroups.Add(userGroup); } catch { MessageBox.Show($"Could not Add {item.GName} to this user", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } IsInProgress = false; App.Current.Dispatcher.Invoke((Action) delegate { window.DialogResult = true; window.Close(); }); } else { MessageBox.Show("Field to add user !!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("Field to add person !!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }) { IsBackground = true }.Start();