예제 #1
0
        public ActionResult orderEdit(order_vm ovm)
        {
            //order table instans
            order_tbl otb = new order_tbl();

            otb.order_id           = ovm.order_id;
            otb.payment_address_1  = ovm.payment_address_1;
            otb.lastname           = ovm.lastname;
            otb.firstname          = ovm.firstname;
            otb.total              = ovm.total;
            otb.customer_id        = ovm.customer_id;
            otb.order_status       = ovm.order_status;
            otb.comment            = ovm.comment;
            otb.date_added         = ovm.date_added;
            otb.invoice_no         = ovm.invoice_no;
            otb.invoice_prefix     = ovm.invoice_prefix;
            otb.email              = ovm.email;
            otb.payment_telephone  = ovm.payment_telephone;
            otb.payment_method     = ovm.payment_method;
            otb.shipping_address_1 = ovm.shipping_address_1;
            otb.shipping_telephone = ovm.shipping_telephone;
            otb.date_modified      = DateTime.Now;
            db.Entry(otb).State    = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("View", new { id = ovm.order_id }));
        }
예제 #2
0
 public static void Mapto2(this order_tbl ord, OrderTableDTO ord1)
 {
     ord.id              = ord1.id;
     ord.createDate      = ord1.createDate;
     ord.updateDate      = ord1.updateDate;
     ord.paymentMethod   = ord1.paymentMethod;
     ord.shippingFee     = ord1.shippingFee;
     ord.shippingAddress = ord1.shippingAddress;
     ord.totalPrice      = ord1.totalPrice;
     ord.status          = ord1.status;
     ord.customerId      = ord1.customerId;
 }
예제 #3
0
 public static OrderTableDTO toorder_tblDTO(this order_tbl ord)
 {
     return(new OrderTableDTO()
     {
         id = ord.id,
         createDate = ord.createDate,
         updateDate = ord.updateDate,
         paymentMethod = ord.paymentMethod,
         shippingFee = ord.shippingFee,
         shippingAddress = ord.shippingAddress,
         totalPrice = ord.totalPrice,
         status = ord.status,
         customerId = ord.customerId
     });
 }
예제 #4
0
        public ActionResult Checkout(checkOut couts)
        {
            int cID;
            //customer object
            customer_tbl ctbl = new customer_tbl();

            //address object
            address_tbl atbl = new address_tbl();

            if (ModelState.IsValid)
            {
                //get user email form
                var user = adb.Users.Find(couts.aspnetuserid);

                //save customer

                ctbl.lastname     = couts.lastname;
                ctbl.firstname    = couts.firstname;
                ctbl.email        = couts.email;
                ctbl.newsletter   = true;
                ctbl.telephone    = couts.telephone;
                ctbl.aspnetuserid = couts.aspnetuserid;
                //save addrerss
                atbl.address_2           = couts.customerAddress;
                atbl.firstname           = couts.firstname;
                atbl.lastname            = couts.lastname;
                atbl.shepingAddress      = couts.shiping_Address;
                atbl.SheppingPhoneNumber = couts.shippingPhoneNumber;



                if ((couts.customer_id == null || couts.customer_id == 0) && (couts.address_id == null || couts.address_id == 0))
                {
                    //for new customer
                    ctbl.date_added = DateTime.Now;


                    //save in custeomer database
                    db.customer_tbl.Add(ctbl);
                    db.SaveChanges();

                    //get user id
                    var c = db.customer_tbl.Find(ctbl.customer_id);

                    //save address in database

                    cID = c.customer_id;
                    atbl.customer_id = cID;
                    db.address_tbl.Add(atbl);
                    db.SaveChanges();
                }
                else
                {
                    ctbl.customer_id     = couts.customer_id;
                    db.Entry(ctbl).State = EntityState.Modified;
                    db.SaveChanges();
                    cID = ctbl.customer_id;
                    atbl.customer_id     = cID;
                    atbl.address_id      = Convert.ToInt32(couts.address_id);
                    db.Entry(atbl).State = EntityState.Modified;
                    db.SaveChanges();
                }

                //user identiiy field
                user.PhoneNumber      = couts.telephone;
                user.UserName         = couts.firstname;
                adb.Entry(user).State = EntityState.Modified;
                adb.SaveChanges();

                //get the payment method
                if (couts.shipping_id != null)
                {
                    var s = db.payment_method_tbl.Find(couts.shipping_id);
                    couts.belingMethod = s.title;
                    couts.sAmount      = Convert.ToDecimal(s.amount);
                    couts.totaltaka   += Convert.ToDouble(s.amount);
                }

                //get the shipping method
                if (couts.sid != null)
                {
                    var s = db.shipping_method.Find(couts.sid);
                    couts.shipping_method = s.Name;
                }


                //now start play with order

                //create order_tbl object
                order_tbl otbl = new order_tbl();

                //save data in order_tbl
                otbl.customer_id        = cID;
                otbl.date_added         = DateTime.Now;
                otbl.email              = couts.email;
                otbl.firstname          = couts.firstname;
                otbl.lastname           = couts.lastname;
                otbl.payment_address_1  = couts.customerAddress;
                otbl.payment_method     = couts.belingMethod;
                otbl.payment_telephone  = couts.telephone;
                otbl.shipping_address_1 = couts.shiping_Address;
                otbl.shipping_telephone = couts.shippingPhoneNumber;
                otbl.total              = Convert.ToDecimal(couts.totaltaka);
                otbl.amont              = couts.sAmount;
                otbl.shipping_method    = couts.shipping_method;
                db.order_tbl.Add(otbl);
                db.SaveChanges();

                //get otbl id

                //get order table id
                var order = db.order_tbl.Find(otbl.order_id);
                //next save prodect data in product order table
                order_product_tbl optbl = new order_product_tbl();


                var ucart = db.userCart_tbl.Where(a => a.userID == user.Id).ToList();

                foreach (var u in ucart)
                {
                    optbl.order_id   = order.order_id;
                    optbl.product_id = u.product_ID;
                    optbl.quantity   = u.Quantity;
                    optbl.dicount    = u.discountPrice;
                    optbl.price      = u.varintPrice + u.mainPrice;
                    optbl.total      = u.totalPrice;
                    optbl.name       = u.productName;
                    optbl.varints    = u.pvvalueID;

                    //save single product
                    db.order_product_tbl.Add(optbl);
                    db.SaveChanges();


                    ////get order_product tbl
                    //var o = db.order_product_tbl.Find(optbl.order_product_id);
                    //if (o.varints != null || o.varints != "null")
                    //{
                    //    List<int> s = JsonConvert.DeserializeObject<List<int>>(o.varints);
                    //    if (s != null)
                    //    {
                    //        foreach (var i in s)
                    //        {
                    //            //update varinat unit

                    //            var pvv = db.product_variant_value.Find(i);
                    //            pvv.quentity -= u.Quantity;
                    //            db.Entry(pvv).State = EntityState.Modified;
                    //            db.SaveChanges();
                    //        }
                    //    }

                    //}

                    ////update product quantity
                    //var p = db.product_tbl.Find(u.product_ID);
                    //p.quantity -= u.Quantity;
                    //db.Entry(p).State = EntityState
                    //    .Modified;
                    //db.SaveChanges();
                }


                //delete cart table data

                foreach (var d in ucart)
                {
                    db.userCart_tbl.Remove(d);
                    db.SaveChanges();
                }
                //add successfully message
                message = "Your Order Is Successfully Complete. We Contect YOu Very Soon Thank you";

                //update quantity
            }
            else
            {
                message = "Insert All Data";
            }

            TempData["message"] = message;
            Session["cart"]     = null;
            return(RedirectToAction("Checkout"));
        }