public void InitUser() { accLevels = Acc_LevelRepository.Acc_Levels; Debug.WriteLine($"User Acc_Lvl: {user.Acc_Lvl}"); if (user.User_Id > 0) { UserCards = new ObservableCollection <Card>(Cards.Where(c => c.User_Id == user.User_Id).Select(c => c)); } user_Photo = new User_Photo { User_Id = user.User_Id }; Debug.WriteLine($"User ID: {user.User_Id}"); if (user.User_Id < 1) { return; } User_PhotoRepository upr = new User_PhotoRepository(); User_Photo up = upr.GetById(user.User_Id); if (up == null || up.Photo == null) { return; } Debug.WriteLine($"Return User ID: {up.User_Id}"); Debug.WriteLine($"Not null User Photo: {up.Photo.Length}"); user_Photo.Photo = up.Photo; }
private static void DeletePhoto(int id) { User_PhotoRepository upr = new User_PhotoRepository(); if (upr.GetById(id) != null) { upr.Delete(id); } }
void SaveUser() { Debug.WriteLine($"SaveUser: {user.Full_Name}"); UserRepository repositrory = new UserRepository(); if (user.User_Id == 0) { user.User_Id = repositrory.Create(user); user_Photo.User_Id = user.User_Id; } else { repositrory.Update(user); } if (user_Photo.Change) { User_PhotoRepository upr = new User_PhotoRepository(); if (user_Photo.Photo != null && user_Photo.Photo.Length > 0) { upr.UpdateOrInsert(user_Photo); } else { User_Photo photo = upr.GetById(user_Photo.User_Id); if (photo != null) { upr.Delete(user_Photo.User_Id); } } } if (UserCards != null && UserCards.Count > 0) { CardRepository cr = new CardRepository(); foreach (var c in UserCards) { Card card = Cards.FirstOrDefault(c => c.Card_Num == SelectedCard.Card_Num); card = c; cr.UpdateOrInsert(c); } } }