public ActionResult Edit([Bind(Include = "P_Id,P_Name,P_Price,P_Quantity,P_Image,CatID_FK")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CatID_FK = new SelectList(db.Categories, "Cat_Id", "Cat_Name", product.CatID_FK);
     return(View(product));
 }
Exemplo n.º 2
0
        public ActionResult EditProduct(Product product)

        {
            HttpPostedFileBase file = Request.Files["ImageData"];

            byte[] imageBytes = null;

            BinaryReader reader = new BinaryReader(file.InputStream);

            imageBytes    = reader.ReadBytes((int)file.ContentLength);
            product.Image = imageBytes;
            if (product.Quantity >= 1)
            {
                product.InStock = true;
            }

            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Admin"));
            }

            return(View(product));
        }
 public ActionResult Edit([Bind(Include = "Cus_Id,Name,Address,Email,Mobile")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Password")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Edit([Bind(Include = "Cat_Id,Cat_Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "Ord_Id,CusID_Fk,Ord_Date")] OrderTable orderTable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderTable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CusID_Fk = new SelectList(db.Customers, "Cus_Id", "Name", orderTable.CusID_Fk);
     return(View(orderTable));
 }
Exemplo n.º 7
0
        public PartialViewResult EditCustomer(Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customer).State = EntityState.Modified;
                db.SaveChanges();

                return(PartialView( ));
            }
            return(PartialView(customer));
        }
 public ActionResult Edit([Bind(Include = "OrDetail_Id,OrdID_FK,ProID_FK,Quantity")] OrderDetail orderDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrdID_FK = new SelectList(db.OrderTables, "Ord_Id", "Ord_Id", orderDetail.OrdID_FK);
     ViewBag.ProID_FK = new SelectList(db.Products, "P_Id", "P_Name", orderDetail.ProID_FK);
     return(View(orderDetail));
 }
Exemplo n.º 9
0
        public ActionResult Checkout(OrderViewModel orderModel, string paymentMethod)
        {
            if (orderModel == null || paymentMethod == null)
            {
                orderModel    = (OrderViewModel)Session["OrderViewModel"];
                paymentMethod = (string)Session["Paymentmethod"];
            }
            else
            {
                Session["OrderViewModel"] = orderModel;
                Session["Paymentmethod"]  = paymentMethod;
            }
            if (paymentMethod == "Paypal")
            {
                APIContext apiContext = PaypalConfiguration.GetAPIContext();
                try
                {
                    string payerId = Request.Params["PayerID"];

                    if (string.IsNullOrEmpty(payerId))
                    {
                        //this section will be executed first because PayerID doesn't exist
                        //it is returned by the create function call of the payment class

                        // Creating a payment
                        // baseURL is the url on which paypal sendsback the data.
                        // So we have provided URL of this controller only
                        string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority +
                                         "/Products/Checkout?";

                        //guid we are generating for storing the paymentID received in session
                        //after calling the create function and it is used in the payment execution

                        var guid = Convert.ToString((new Random()).Next(100000));

                        //CreatePayment function gives us the payment approval url
                        //on which payer is redirected for paypal account payment

                        var createdPayment = CreatePayment(apiContext, baseURI + "guid=" + guid, (List <CartItemModel>)Session["cart"]);

                        //get links returned from paypal in response to Create function call

                        var links = createdPayment.links.GetEnumerator();

                        string paypalRedirectUrl = null;

                        while (links.MoveNext())
                        {
                            Links lnk = links.Current;

                            if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                            {
                                //saving the payapalredirect URL to which user will be redirected for payment
                                paypalRedirectUrl = lnk.href;
                            }
                        }

                        // saving the paymentID in the key guid
                        Session.Add(guid, createdPayment.id);

                        return(Redirect(paypalRedirectUrl));
                    }
                    else
                    {
                        // This section is executed when we have received all the payments parameters
                        // from the previous call to the function Create
                        // Executing a payment

                        var guid = Request.Params["guid"];

                        var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                        if (executedPayment.state.ToLower() != "approved")
                        {
                            return(View("FailureView"));
                        }
                        else
                        {
                            int total = 0;
                            foreach (var cartItem in (List <CartItemModel>)Session["cart"])
                            {
                                total = total + (cartItem.productPrice * cartItem.productQuantity);
                            }
                            Models.Order order             = new Models.Order();
                            var          currentOrderModel = (OrderViewModel)Session["OrderViewModel"];
                            order.FullName        = currentOrderModel.Fullname;
                            order.Phone           = currentOrderModel.PhoneNumber;
                            order.Email           = currentOrderModel.Email;
                            order.ShippingAddress = currentOrderModel.ShippingAddress;
                            order.Total           = total;
                            order.PaymentMethod   = (string)Session["Paymentmethod"];
                            order.CreatedDate     = DateTime.Now;
                            db.Orders.Add(order);
                            db.SaveChanges();
                            int orderID = db.Orders.OrderByDescending(i => i.CreatedDate).Select(i => i.OrderID).First();
                            foreach (var item in (List <CartItemModel>)Session["cart"])
                            {
                                OrderDetail orderDetail = new OrderDetail();
                                orderDetail.OrderID   = orderID;
                                orderDetail.ProductID = item.productID;
                                orderDetail.Quantity  = item.productQuantity;
                                orderDetail.UnitPrice = item.productPrice;
                                orderDetail.TotalUnit = item.productPrice * item.productQuantity;
                                db.OrderDetails.Add(orderDetail);
                                var productColor        = db.ProductColors.Where(i => (i.ProductID == item.productID) && (i.ColorName == item.productColor)).First();
                                int updateColorQuantity = productColor.QuantityInStock.Value - item.productQuantity;
                                productColor.QuantityInStock = updateColorQuantity;
                                db.Entry(productColor).State = EntityState.Modified;
                            }
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    return(View("PaymentFailure"));
                }
                return(View("PaymentSuccess"));
            }
            else if (paymentMethod == "CashOnDelivery")
            {
                Session["cart"] = null;
                return(View("CashOnDelivery"));
            }
            return(View());
        }