예제 #1
0
 public ActionResult Signup(tblUser tb)
 {
     _db.tblUsers.Add(tb);
     _db.SaveChanges();
     ViewBag.Message = "Successfully Created Account";
     return(View());
 }
예제 #2
0
        public RedirectToRouteResult EditOrder(int?id)
        {
            Order order = db.Orders.Find(id);

            order.IsShipped = true;
            db.SaveChanges();
            return(RedirectToRoute(new { controller = "Admin", action = "Index" }));
        }
        public ActionResult Create([Bind(Include = "Cus_Id,Name,Address,Email,Mobile")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "Id,UserName,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
        public ActionResult Create([Bind(Include = "Cat_Id,Cat_Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult Create([Bind(Include = "Ord_Id,CusID_Fk,Ord_Date")] OrderTable orderTable)
        {
            if (ModelState.IsValid)
            {
                db.OrderTables.Add(orderTable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CusID_Fk = new SelectList(db.Customers, "Cus_Id", "Name", orderTable.CusID_Fk);
            return(View(orderTable));
        }
        public ActionResult Create([Bind(Include = "OrDetail_Id,OrdID_FK,ProID_FK,Quantity")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetails.Add(orderDetail);
                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));
        }
예제 #8
0
 public ActionResult CheckOut(Customer data)
 {
     if (ModelState.IsValid == true)
     {
         var Record = db.Customers.Add(data);
         db.SaveChanges();
     }
     return(View());
 }
예제 #9
0
 public ActionResult Register(UserRegister user)
 {
     if (ModelState.IsValid)
     {
         if (CheckDuplicate(user.Email))
         {
             EncryptData encypt            = new EncryptData();
             string      encryptedPassword = encypt.EncryptPassword(user.Password);
             try
             {
                 User newUser = new Models.User();
                 newUser.UserName = user.UserName;
                 newUser.Password = encryptedPassword;
                 newUser.Email    = user.Email;
                 newUser.Role     = 1;
                 db.Users.Add(newUser);
                 db.SaveChanges();
                 Session["UserID"]   = user.UserID;
                 Session["Username"] = user.UserName;
             }
             catch (DbEntityValidationException ex)
             {
                 Exception raise = ex;
                 foreach (var validationErrors in ex.EntityValidationErrors)
                 {
                     foreach (var validationError in validationErrors.ValidationErrors)
                     {
                         string message = string.Format("{0}:{1}",
                                                        validationErrors.Entry.Entity.ToString(),
                                                        validationError.ErrorMessage);
                         // raise a new exception nesting
                         // the current instance as InnerException
                         raise = new InvalidOperationException(message, raise);
                     }
                 }
                 throw raise;
             }
             return(RedirectToAction("Index"));
         }
     }
     ModelState.AddModelError(string.Empty, "You email is duplicated, please choose another email address");
     return(View(user));
 }
예제 #10
0
        public ActionResult CheckOutNow(int?id, Cart cart)
        {
            Customer customer = db.Customers.Find(id);

            if (customer == null)
            {
                customer           = new Customer();
                customer.FirstName = Convert.ToString(Request["txtFirstName"]);
                Debug.WriteLine(customer.FirstName);
            }
            else
            {
                Order order = new Order();
                order.CustomerId = customer.Id;
                order.Amount     = cart.totalValue();
                order.Date       = DateTime.Now;
                order.IsShipped  = false;
                db.Orders.Add(order);
                db.SaveChanges();

                foreach (var line in cart.Lines)
                {
                    OrderDetail detail = new OrderDetail();
                    detail.OrderId   = order.Id;
                    detail.ProductId = line.Product.Id;
                    detail.Quantity  = line.Quantity;
                    detail.Price     = line.Quantity * (decimal)line.Product.Price;

                    Product product = db.Products.Single(p => p.Id == line.Product.Id);
                    product.Quantity -= line.Quantity;

                    db.SaveChanges();
                    db.OrderDetails.Add(detail);
                    db.SaveChanges();
                }
            }
            cart.Clear();
            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "P_Id,P_Name,P_Price,P_Quantity,P_Image,CatID_FK")] Product product, HttpPostedFileBase ImageFile)
        {
            if (ModelState.IsValid)
            {
                string path = UploadImage(ImageFile);
                if (path == "-1")
                {
                }
                else
                {
                    product.P_Image = path;
                    db.Products.Add(product);
                    db.SaveChanges();
                }

                //db.Products.Add(product);
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CatID_FK = new SelectList(db.Categories, "Cat_Id", "Cat_Name", product.CatID_FK);
            return(View(product));
        }
예제 #12
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());
        }