Пример #1
0
        public async Task <ActionResult> MakePayment(OrderPaymentVm model)
        {
            if (ModelState.IsValid)
            {
                //var totalSale = await storeDB.Sales.AsNoTracking().CountAsync();
                //var saleId = totalSale + 1;


                var sale = new Sale
                {
                    CustomerId = model.CustomerId,
                    Total      = model.TotalAmount,
                    IsPayed    = false,
                    SaleDate   = DateTime.Now
                };
                storeDB.Sales.Add(sale);
                await storeDB.SaveChangesAsync();

                //Process the order
                var cart = ShoppingCart.GetCart(this.HttpContext);
                sale = cart.CreateOrder(sale);
                var testOrLiveSecret = ConfigurationManager.AppSettings["PayStackSecret"];
                var api = new PayStackApi(testOrLiveSecret);
                // Initializing a transaction
                //var response = api.Transactions.Initialize("*****@*****.**", 5000000);
                var transactionInitializaRequest = new TransactionInitializeRequest
                {
                    //Reference = "SwifKampus",
                    AmountInKobo = _query.ConvertToKobo((int)model.TotalAmount),
                    CallbackUrl  = "http://localhost:59969/Checkout/ConfrimPayment",
                    Email        = model.Email,
                    Bearer       = "Ajaoko Order Payment",

                    CustomFields = new List <CustomField>
                    {
                        new CustomField("customerid", "customerid", model.CustomerId),
                        new CustomField("amount", "amount", model.TotalAmount.ToString(CultureInfo.InvariantCulture)),
                        new CustomField("saleid", "saleid", sale.SaleId.ToString())
                    }
                };
                var response = api.Transactions.Initialize(transactionInitializaRequest);

                if (response.Status)
                {
                    //redirect to authorization url
                    return(RedirectPermanent(response.Data.AuthorizationUrl));
                    // return Content("Successful");
                }
                return(Content("An error occurred"));
            }
            return(RedirectToAction("AddressAndPayment"));
        }
Пример #2
0
        public async Task <ActionResult> Create([Bind(Include = "ProductId,MerchantId,CategoryId,Name,AlternativeName,Price,Quantity,Unit,OtherUnitName,Description,ProductDiscount,DiscountPrice,IsApproved,DateAdded,StockQuantity,InternalImage,ItemPictureUrl")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
            ViewBag.MerchantId = new SelectList(db.Merchants, "MerchantId", "CompanyName", product.MerchantId);
            return(View(product));
        }
Пример #3
0
        public async Task <ActionResult> Create(Supplier supplier, int[] products)
        {
            if (products != null)
            {
                foreach (var ID in products)
                {
                    Product product = _db.Products.Find(ID);
                    supplier.Products.Add(product);
                }
            }
            _db.Suppliers.Add(supplier);
            await _db.SaveChangesAsync();

            return(View("Index", _db.Suppliers));
        }
Пример #4
0
        public async Task <ActionResult> Create(ShippingDetail shippingDetail)
        {
            if (ModelState.IsValid)
            {
                db.ShippingDetails.Add(shippingDetail);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "ShoppingCart"));
            }
            var id = User.Identity.GetUserId();

            ViewBag.CustomerId = new SelectList(db.Customers.AsNoTracking()
                                                .Where(x => x.CustomerId.Equals(id)), "CustomerId", "FullName");
            return(View(shippingDetail));
        }
Пример #5
0
        public async Task <ActionResult> Create(Stock stock)
        {
            string messag1 = "";
            string messag2 = "";

            if (ModelState.IsValid)
            {
                stock.Date = DateTime.Now;
                _db.Stocks.Add(stock);
                //User myUser = myDBContext.Users.SingleOrDefault(user => user.Username == username);
                //var user = _db.Users.Where(c => c.Email.Equals(model.Email)).SingleOrDefault();
                //Product product = await _db.Products.FindAsync(int.Parse(stock.Name));
                Product product = await _db.Products.SingleOrDefaultAsync(s => s.ProductId.Equals(stock.ProductId));

                if (product == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    int incomingValue = stock.Quantity;

                    if (product.StockQuantity == null)
                    {
                        product.StockQuantity = 0;
                    }

                    if (stock.Status.Equals(PopUp.Status.Add))
                    {
                        product.StockQuantity += incomingValue;
                    }
                    else if (stock.Status.Equals(PopUp.Status.Remove))
                    {
                        product.StockQuantity -= incomingValue;
                    }
                }
                if (product.StockQuantity < 0)
                {
                    messag1 = "Sorry stock Removal is UNSUCCESSFUL";
                    messag2 = "You should have more item to subtract from";
                    return(RedirectToAction("Index", new { val1 = messag1, val2 = messag2 }));
                    //return RedirectToAction("Details", "Consultants", new { id = pescription.ConsultantID });
                }
                else
                {
                    messag1 = "Successfully Updated";
                    _db.Entry(product).State = EntityState.Modified;
                    await _db.SaveChangesAsync();

                    return(RedirectToAction("Index", new { val1 = messag1 }));
                }
            }

            return(View(stock));
        }