public IActionResult Create(int card) { _context.Accounts.Add(new Account { CardId = card, IsBlocked = false, Balance = _context.Cards.FirstOrDefault(c => c.CardId == card).Balance }); _context.SaveChanges(); return(RedirectToAction("Main", "Users")); }
public ActionResult Create(Category category) //[Bind(Include = "ID,Name,IsActive")] Category category) { if (ModelState.IsValid) { _dbContext.Categories.Add(category); _dbContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
/// <summary> /// Adds a payment to the database in a "InProgress" state. /// </summary> /// <param name="payment"></param> public void Add(PaymentData payment) { payment.TransactionDate = DateTime.Now; // Set it with the current date / time. var paymentToAdd = _uniqueIdBuilder.HydratePaymentId(payment); //Create a uniqueID paymentToAdd.Status = PaymentStatus.InProgresss; if (_context.PaymentData.Where(p => p.PaymentId == paymentToAdd.PaymentId).Count() == 0) // Prevent duplicate payments being added to the repository. This is dependent on the hashing mechanism making uniqueId's. { _context.Add(paymentToAdd); _context.SaveChanges(); } }
public MerchantsRepository(PaymentsContext paymentsContext) { _paymentsContext = paymentsContext; if (!_paymentsContext.Merchants.Any()) { _paymentsContext.AddRange( new Merchant { ApiKey = "84e3868bd19b48d7b2c2c1a420afca96", EncryptionKey = "abcd1234$%^&8765£$%^poiu", CompanyName = "PaperShop", ContactName = "Ian Papier", EmailAddress = "*****@*****.**", }, new Merchant { ApiKey = "51453ab10b194cea9004da4501f846fc", EncryptionKey = "8765£$%^poiuabcd1234$%^&", CompanyName = "Peanuts R Us", ContactName = "Alex Nutter", EmailAddress = "*****@*****.**", }); _paymentsContext.SaveChanges(); } }
public IActionResult Create(double balance) { if (balance > 0) { _context.Cards.Add(new Card { Balance = balance, UserId = _context.Users.FirstOrDefault(x => x.Email == User.Identity.Name).UserId }); _context.SaveChanges(); return(RedirectToAction("Main", "Users")); } else { ViewBag.Message = "Balance cannot be negative or zero!"; return(View("Error")); } }
public IActionResult Add(string goal) { if (_context.Goals.Where(x => x.GoalName == goal).Count() == 0) { _context.Goals.Add(new Goal { GoalName = goal }); _context.SaveChanges(); return(RedirectToAction("MainAdmin", "Users")); } else { ViewBag.Message = "This goal already exists!"; return(View("Error")); } }
public static void Seed(DbContextOptions <PaymentsContext> options) { using (var context = new PaymentsContext(options)) { context.ProductLocales.AddRange(PaymentsStaticDataProdiver.ProductLocales); context.Products.AddRange(PaymentsStaticDataProdiver.Products); context.SaveChanges(); } }
public ActionResult Create(Payment payment, string payFrom) { if (!ModelState.IsValid) { return(RedirectToAction("Index", "Home", new { errorMessage = "Invalid Model can't be save!" })); } else { if (!payFrom.Equals("NONE", StringComparison.OrdinalIgnoreCase)) { var paymentSourceCatId = _dbContext.Categories?.FirstOrDefault(c => c.Name == payFrom)?.ID ?? 0; if (paymentSourceCatId == 0 || paymentSourceCatId == payment.CatogoryId) { return(RedirectToAction("Index", "Home", new { errorMessage = $"Invalid payment Source Category : {payFrom} and can't be save!" })); } else { _dbContext.Payments.Add(new Payment { Amount = payment.Amount * (-1), CatogoryId = paymentSourceCatId, Description = payment.Description, PayDate = DateTime.UtcNow.AddHours(3) }); _dbContext.SaveChanges(); } } _dbContext.Payments.Add(payment); _dbContext.SaveChanges(); return(RedirectToAction("Index", new { id = 2 })); } }
public IActionResult Registration(string name, string surname, string email, string password) { if (_context.Users.Where(u => u.Email.Equals(email)).Count() == 0) { _context.Users.Add(new User { Name = name, Surname = surname, Email = email, IsAdmin = false, Password = password }); _context.SaveChanges(); return(View("Login")); } else { ViewBag.Message = "User with this email exists, use other email or login with correct data!"; return(View("Error")); } }
public IActionResult Pay(int goal, int account, double amount) { if (amount > 0) { var currentAcc = _context.Accounts.FirstOrDefault(acc => acc.AccountId == account); if (!currentAcc.IsBlocked) { using (var transaction = _context.Database.BeginTransaction()) { currentAcc.Balance -= amount; if (currentAcc.Balance >= 0) { _context.Cards.FirstOrDefault(card => card.CardId == currentAcc.CardId).Balance -= amount; _context.Payments.Add(new Payment { AccountId = currentAcc.AccountId, Amount = amount, Date = DateTime.Now.ToShortDateString(), GoalId = goal }); _context.SaveChanges(); transaction.Commit(); } else { transaction.Rollback(); ViewBag.Message = "You cant make payment from this account! No resources."; return(View("Error")); } } } else { ViewBag.Message = "This account is blocked, operation unavailable!"; return(View("Error")); } return(RedirectToAction("Main", "Users")); } else { ViewBag.Message = "Incorrect payment amount!!!"; return(View("Error")); } }
public void Save() { _paymentsContext.SaveChanges(); }
public static void Initialize(PaymentsContext context) { if (!context.Users.Any()) { context.Users.AddRange( new User { IsAdmin = false, Name = "Nikolay", Surname = "Amusin", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = true, Name = "Ivan", Surname = "Ivanov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Kirill", Surname = "Stepanov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Andrei", Surname = "Spiridonov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Ivan", Surname = "Litvinov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Alexei", Surname = "Platonov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Nikolay", Surname = "Andreev", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Konstantin", Surname = "Kom", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = true, Name = "Konstantin", Surname = "Kurochka", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = true, Name = "Igor", Surname = "Stefanovskiy", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Kirill", Surname = "Sidorov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Kseniya", Surname = "Zlotnikova", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Ilya", Surname = "Puninskiy", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Alexandr", Surname = "Anosov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Nikolay", Surname = "Ropot", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Ivan", Surname = "Kosov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Oleg", Surname = "Ivanov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Alexey", Surname = "Kachan", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Sergei", Surname = "Gusakov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Alexandr", Surname = "Obrezkov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Dmitriy", Surname = "Kozintsov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Oleg", Surname = "Asenchik", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Pavel", Surname = "Shur", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Viktoriya", Surname = "Belous", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Vladislav", Surname = "Volotkovich", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = true, Name = "Denis", Surname = "Trubenok", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Alesya", Surname = "Lizogub", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Vitaliy", Surname = "Belodedov", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Diana", Surname = "Korniluk", Email = "*****@*****.**", Password = "******" }, new User { IsAdmin = false, Name = "Yana", Surname = "Kislyak", Email = "*****@*****.**", Password = "******" }); context.SaveChanges(); } double[] balances = new Double[1300]; for (int i = 0; i < balances.Length; i++) { balances[i] = new Random().Next(20, 250); } if (!context.Cards.Any()) { for (int i = 1, k = 0; i <= 30; i++) { for (int j = 0; j < 35; j++, k++) { context.Cards.Add(new Card { UserId = i, Balance = balances[k] }); } } context.SaveChanges(); } if (!context.Accounts.Any()) { for (int i = 1, j = 0; i <= 1000; i++, j++) { context.Accounts.Add(new Account { CardId = i, IsBlocked = false, Balance = balances[j] }); } context.SaveChanges(); } if (!context.Goals.Any()) { context.Goals.AddRange( new Goal { GoalName = "Learning" }, new Goal { GoalName = "Gym" }, new Goal { GoalName = "BRSM" }, new Goal { GoalName = "TV" }, new Goal { GoalName = "Phone" }, new Goal { GoalName = "Bank" }, new Goal { GoalName = "Shop" }, new Goal { GoalName = "Oil" }, new Goal { GoalName = "Tax" }, new Goal { GoalName = "Credit" }, new Goal { GoalName = "Penalty" }, new Goal { GoalName = "Cinema" }, new Goal { GoalName = "Teacher" }, new Goal { GoalName = "Software" }, new Goal { GoalName = "Retake" }, new Goal { GoalName = "Communal" }, new Goal { GoalName = "Home" }, new Goal { GoalName = "Pool" }, new Goal { GoalName = "Referee" }, new Goal { GoalName = "Project" }, new Goal { GoalName = "Water" }, new Goal { GoalName = "Hostel" }, new Goal { GoalName = "Dormitory" }, new Goal { GoalName = "Mortage" }, new Goal { GoalName = "Game" }, new Goal { GoalName = "Microsoft Office" }, new Goal { GoalName = "Matlab" }, new Goal { GoalName = "Notebook" }, new Goal { GoalName = "Garage" }, new Goal { GoalName = "Parking" }); context.SaveChanges(); } if (!context.Payments.Any()) { for (int i = 1; i <= 1000; i++) { context.Payments.Add(new Payment { AccountId = new Random().Next(1, 1000), GoalId = new Random().Next(1, 30), Date = "01/01/201" + new Random().Next(1, 9), Amount = new Random().Next(10, 150) }); } context.SaveChanges(); } }
public static void InitializeDbForTests(PaymentsContext db) { db.Accounts.AddRange(GetAccounts()); db.PaymentRequests.AddRange(GetPaymentRequests()); db.SaveChanges(); }