public void Delete(Client client) { using (IDataContextWrapper dataContext = _dataContextLocator()) { var clientEntity = dataContext.Table <Client>().First(x => x.Id == client.Id); IsoStorageHelper.DeleteFile(clientEntity.Photo); dataContext.DeleteOnSubmit(clientEntity); dataContext.SubmitChanges(); } Clients.Remove(client); }
void UploadCallback(SkyDriveResult <bool> result) { ShowLoading = false; dbStream.Close(); IsoStorageHelper.DeleteFile("ClientsManager_backup.sdf"); if (result.Succeded) { GoBack(); MessageBox.Show("Backup has been uploaded."); } else { MessageBox.Show("Error occured while uploading backup: \n" + result.Exception.Message); } }
public void Save() { if (!string.IsNullOrWhiteSpace(Forename) || !string.IsNullOrWhiteSpace(Surname)) { if (Latitude != null && (Latitude < -90.0 || Latitude > 90.0)) { MessageBox.Show("Incorrect latitude."); return; } if (Longitude != null && (Longitude < -180.0 || Longitude > 180.0)) { MessageBox.Show("Incorrect longitude."); return; } using (IDataContextWrapper dataContext = _dataContextLocator()) { Group selectedGroup = dataContext.Table <Group>().FirstOrDefault(x => x.Id == Group.Id); DateTime?onlyDate = Birthdate.HasValue ? new DateTime?(Birthdate.Value.Date) : Birthdate; if (IsAdding) { Client newClient = new Client() { Forename = this.Forename, Surname = this.Surname, Birthdate = onlyDate, Longitude = this.Longitude, Latitude = this.Latitude, IsActive = this.IsActive, Group = selectedGroup }; dataContext.InsertOnSubmit(newClient); if (!String.IsNullOrEmpty(lastPhotoName) && Photo != null) { dataContext.SubmitChanges(); newClient.Photo = IsoStorageHelper.SavePhoto(Photo, newClient.Id, lastPhotoName); } } else { Client clientToEdit = dataContext.Table <Client>().FirstOrDefault(x => x.Id == ClientId); if (clientToEdit != null) { clientToEdit.Surname = Surname; clientToEdit.Forename = Forename; clientToEdit.Birthdate = onlyDate; clientToEdit.Longitude = Longitude; clientToEdit.Latitude = Latitude; clientToEdit.IsActive = IsActive; clientToEdit.Group = selectedGroup; if (Photo == null) { IsoStorageHelper.DeleteFile(clientToEdit.Photo); //delete old photo clientToEdit.Photo = null; } else { if (!String.IsNullOrEmpty(lastPhotoName)) //if new photo were chosen { IsoStorageHelper.DeleteFile(clientToEdit.Photo); //delete old photo clientToEdit.Photo = IsoStorageHelper.SavePhoto(Photo, clientToEdit.Id, lastPhotoName); } } } } dataContext.SubmitChanges(); } GoBack(); } else { MessageBox.Show("Client must have Forename or Surname"); } }