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; }
public void Add(User_Photo photo) { try { using (EFContext context = new EFContext()) { context.Photos.Add(photo); context.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
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); } } }
private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); string imageName = Guid.NewGuid().ToString() + ".jpg"; //08f71055-72b0-4075-bbc9-8472782e3b7f.jpg System.Drawing.Image img = System.Drawing.Image.FromFile(dlg.FileName); img = CompressImage.CreateImage((Bitmap)img, 500, 500); img.Save(Environment.CurrentDirectory + "//" + imageName, ImageFormat.Jpeg); Data.Models.User_Photo user_Photo = new User_Photo(); { user_Photo.Name = imageName; user_Photo.User_Id = StartWindow.selectID; } PhotoService photoService = new PhotoService(); photoService.Add(user_Photo); }
public void UpdateOrInsert(User_Photo user) { using OdbcConnection db = new OdbcConnection(connectionString); db.Execute(updateOrInsertUser_PhotoSQL, user); }