Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,Name,IsActive")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,PayDate,Amount,Description,CatogoryId")] Payment payment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(payment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CatogoryId"] = new SelectList(_context.Categories, "ID", "Name", payment.CatogoryId);
            return(View(payment));
        }
        /// <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();
            }
        }