public ActionResult KreditKartenZahlung(KreditKartenZahlungVM vm) { var result = DAL.Logic.Helper.IsCCValid(vm.KartenNr); if (result == true) { //Hier muss man nun anhand der Diamantenpackid den Eintrag in die DB machen //1. Hole alle Diamantenpackinfos DiamantenPack diamantenpack = ShopManager.GetDiamantenPackById(vm.IdDiamantenPack); //2. Addiere die Anzahl an Diamanten vom Diamantenpack zum User ShopManager.AddDiamondsToUser(User.Identity.Name, (int)diamantenpack.Diamanten); //3. Trage den Kauf des Diamantenpacks in VirtualPurchases ein ShopManager.InsertVirtualDiamondPurchase(User.Identity.Name, vm.IdDiamantenPack); TempData["ConfirmMessage"] = "Sie haben" + " " + diamantenpack.Diamanten + " " + "Diamanten gekauft"; return(RedirectToAction("BestellungDanke", "Shop")); } else { TempData["ErrorMessage"] = "Ungültige Kartennummer!"; return(View(vm)); } }
public static BuyResult ExecuteDiamantenOrder(int idPerson, int idDiaPack) { BuyResult result = BuyResult.Success; using (var db = new CardGame_v2Entities()) { VirtualPurchase diaOrder = new VirtualPurchase(); diaOrder.ID_DiamantenPack = idDiaPack; diaOrder.ID_User = idPerson; diaOrder.PurchaseDate = DateTime.Now; diaOrder.NumberOfPacks = 1; db.AllVirtualPurchases.Add(diaOrder); db.SaveChanges(); User user = db.AllUsers.FirstOrDefault(x => x.ID == idPerson); DiamantenPack pack = db.AllDiamantenPacks.FirstOrDefault(x => x.ID == idDiaPack); if (user.AmountMoney < pack.PackPrice) { result = BuyResult.NotEnoughMoney; } else { /// ziehe Preis vom pack beim User ab! user.AmountMoney += (int)pack.Diamanten; db.SaveChanges(); } } return(result); }
public ActionResult BuyDiamanten(int id) { var dbDiamantenPack = ShopManager.GetDiamantenPackById(id); DiamantenPack diamantenpack = new DiamantenPack(); diamantenpack.ID = dbDiamantenPack.ID; diamantenpack.Diamanten = dbDiamantenPack.Diamanten; diamantenpack.PackPrice = dbDiamantenPack.PackPrice; return(View(diamantenpack)); }
public ActionResult DiamantenpackErwerben(int idDiamantenPack) { //hole Diamenteninfos über id DiamantenPack diamanten = ShopManager.GetDiamantenPackById(idDiamantenPack); KreditKartenZahlungVM kvm = new KreditKartenZahlungVM(); kvm.Preis = diamanten.PackPrice; kvm.AnzahlDiamanten = (int)diamanten.Diamanten; kvm.IdDiamantenPack = diamanten.ID; //return RedirectToAction("KreditKartenZahlung", idDiamantenPack); return(View("KreditKartenZahlung", kvm)); }
public static DiamantenPack GetDiamantenPackById(int id) { var dbDiamantenPack = new DiamantenPack(); try { using (var db = new CardGame_v2Entities()) { dbDiamantenPack = db.AllDiamantenPacks.Find(id); } if (dbDiamantenPack == null) { throw new Exception("CardPackNotFound"); } } catch (Exception e) { Writer.LogError(e); } return(dbDiamantenPack); }