public List<User> GetAllUsersWithCards(List<Card> cards ) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; var users = GetAllUsers(); List<User> usersWithCards = new List<User>(); foreach (var user in users) { bool done = false; foreach (var card in cards) { if (!done) { if (user.Id == card.CreatedUserId) { usersWithCards.Add(user); done = true; } } } } return usersWithCards; } }
public User GetUserByUsername(string username) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.User.FirstOrDefault(x => x.Username == username); } }
public User GetUserByPhoneNumber(string phoneNumber) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.User.FirstOrDefault(x => x.PhoneNumber == phoneNumber); } }
public User GetUserById(int id) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.User.FirstOrDefault(x => x.Id == id); } }
public List<Card> GetAllCardsByPhoneNumber(string phoneNumber) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.Card.Where(x => x.IsDeleted == false && x.User.PhoneNumber == phoneNumber).ToList(); } }
public List<User> GetAllUsers() { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.User.ToList(); } }
public List<Card> GetAllCardsById(int id) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.Card.Where(x => x.IsDeleted == false && x.User.Id == id).ToList(); } }
public void Add(User user) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; db.User.Add(user); db.SaveChanges(); } }
public void CreateCardImage(CardImage cardImage) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; db.CardImage.Add(cardImage); db.SaveChanges(); } }
public void Delete(int id) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; Card card = GetCard(id); card.IsDeleted = true; Update(card); } }
public void Add(Card card) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; card.User = null; // Lappeløsning.. ellers blev en ny bruger oprettet hver gang // card.EncodedImage = "ÆNDRET I DAL"; db.Card.Add(card); db.SaveChanges(); } }
/*public void Delete(int id) { using (var db = new BusinessCardScannerEntities()) { User user = GetUser(id); user.IsDeleted = true; Update(user); } }*/ public void Update(User user) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } }
public CardImage GetImageByEncodedImage(string encodedImage) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.CardImage.FirstOrDefault(x => x.EncodedImage.Equals(encodedImage)); } }
public string GetEncodedImage(int id) { using (var db = new BusinessCardScannerEntities()) { db.Configuration.ProxyCreationEnabled = false; return db.CardImage.First(x => x.Id == id).EncodedImage; } }