public ActionResult ActivateUser(string id) { try { //1. In DB nach entsprechenden String suchen //2. Wenn gefunden, den zugehörigen Benutzer aktivieren, //3. GUID aus DB loeschen using (var db = new CardGame_v2Entities()) { //1 var dbUser = db.AllUsers.Where(u => u.activationCode.ToString() == id).FirstOrDefault(); if (dbUser == null) { return(RedirectToAction("Index", "Home")); } //2 dbUser.Active = true; //3 dbUser.activationCode = null; //4 db.Entry(dbUser).State = EntityState.Modified; db.SaveChanges(); } } catch { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Login")); }
public static void SaveUser(User dbUser) { using (var db = new CardGame_v2Entities()) { db.Entry(dbUser).State = EntityState.Modified; db.SaveChanges(); } }
public static bool AddCardsToCollectionByEmail(string email, List <Card> cards) { var dbUser = new User(); try { using (var db = new CardGame_v2Entities()) { dbUser = db.AllUsers.Where(u => u.Mail == email).FirstOrDefault(); if (dbUser == null) { throw new Exception("UserDoesNotExist"); } foreach (var c in cards) { var userCC = (from coll in db.AllUserCardCollections where coll.ID_Card == c.ID && coll.ID_User == dbUser.ID select coll) .FirstOrDefault(); if (userCC == null) //User does not own card, add to collection { var cc = new UserCardCollection(); cc.Card = db.AllCards.Find(c.ID); cc.User = dbUser; cc.NumberOfCards = 1; dbUser.AllUserCardCollections.Add(cc); db.SaveChanges(); } else //User owns card, add to num { userCC.NumberOfCards += 1; db.Entry(userCC).State = EntityState.Modified; db.SaveChanges(); } } //db.SaveChanges(); return(true); } } catch (Exception e) { Writer.LogError(e); return(false); } }
public static List <Card> GetCardsForDeck(int idDeck) { List <Card> deckCards = null; try { using (var context = new CardGame_v2Entities()) { Deck deck = context.AllDecks.FirstOrDefault(x => x.ID == idDeck); if (deck != null) { User currentUser = deck.User; /// ermittle alle userCardCollections für diesen User List <UserCardCollection> userCardCollections = currentUser.AllUserCardCollections.ToList(); foreach (var ucc in userCardCollections) { /// Schau nach ob diese karte auch bereits in diesem Deck ist DeckCard deckCard = context.AllDeckCards.FirstOrDefault(x => x.ID_Card == ucc.ID_Card && x.ID_Deck == idDeck); /// wenn diese karte bereits im gewünschten Deck verwendet wird if (deckCard != null) { ucc.NumberOfCards -= deckCard.NumberOfCards; // dann verringere die Anzahl } } /// gib nur die Karten zurück die man noch verwenden kann deckCards = userCardCollections.Where(x => x.NumberOfCards > 0).Select(x => x.Card).ToList(); /// lade nachträglich alle zugeordneten CardType Objekte /// alternativ: bereits beim Zugriff via context auf Datenbank /// mit Include alle notwendigen Elemente raus laden deckCards.ForEach(x => context.Entry(x).Reference("CardType").Query().Load()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debugger.Break(); } return(deckCards); }
public static bool UpdateBalanceByEmail(string email, int newBalance) { var dbUser = GetUserByEmail(email); dbUser.AmountMoney = newBalance; try { using (var db = new CardGame_v2Entities()) { db.Entry(dbUser).State = EntityState.Modified; db.SaveChanges(); return(true); } } catch (Exception e) { Writer.LogError(e); return(false); } }
public ActionResult EditAccount(Register user) { var reguser = UserManager.GetUserByEmail(User.Identity.Name); reguser.ID = user.ID; reguser.FirstName = user.Firstname; reguser.LastName = user.Lastname; reguser.Mail = user.Email; reguser.GamerTag = user.Gamertag; //reguser.Street = user.Street; //reguser.Streetnumber = (int)user.Streetnumber; //reguser.Post_Code = user.PLZ; //reguser.City = user.City; using (var db = new CardGame_v2Entities()) { db.Entry(reguser); db.SaveChanges(); return(View(reguser)); } }