public ActionResult Create()
        {
            if (Session["cart"] != null)
            {
                order d1 = new order {
                    userId = User.Identity.GetUserId(), order_state = false
                };

                foreach (var i in (List <order_item>)Session["cart"])
                {
                    order_item item1 = new order_item {
                        order_id = d1.Id, book_id = i.book.Id, Price = i.Price, Quantity = i.Quantity
                    };
                    BookStoreDB.order_items.Add(item1);
                }
                if (ModelState.IsValid)
                {
                    BookStoreDB.orders.Add(d1);
                    BookStoreDB.SaveChanges();

                    Session["cart"] = null;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }
Example #2
0
 public ActionResult Create(order_item orderItem)
 {
     if (ModelState.IsValid)
     {
         BookStoreDB.order_items.Add(orderItem);
         BookStoreDB.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Example #3
0
 public static void Mapto1(this order_item ori, order_itemDTO ori1)
 {
     ori.id           = ori1.id;
     ori.orderTableId = ori1.orderTableId;
     ori.skuId        = ori1.skuId;
     ori.name         = ori1.name;
     ori.variation    = ori1.variation;
     ori.price        = ori1.price;
     ori.quantity     = ori1.quantity;
 }
Example #4
0
 public static order_itemDTO toorder_itemDTO(this order_item ori1)
 {
     return(new order_itemDTO()
     {
         id = ori1.id,
         orderTableId = ori1.orderTableId,
         skuId = ori1.skuId,
         name = ori1.name,
         variation = ori1.variation,
         price = ori1.price,
         quantity = ori1.quantity
     });
 }
        private List<order_item> GetOrderItem(int ServiceProviderId)
        {
            List<order_item> ReturnList = new List<order_item>();
            foreach (OrderItem OI in SyncClient.GetOrderItem(GetFromDate, DateTimeNow, ServiceProviderId))
            {
                order_item tmp = QueryOrderItem(OI.Id);
                Boolean NewValue = false;
                if (tmp == null)
                {
                    tmp = new order_item();
                    NewValue = true;
                }

                tmp.Id = OI.Id;
                tmp.addittional_cost = OI.AddCost;
                tmp.createdAt = System.DateTime.Parse(OI.CreateDat);
                tmp.final_price = OI.FinalPrice;
                tmp.final_price_without_tax = OI.FinalPriceWithoutTax;
                tmp.final_price_with_tax = OI.FinalPriceWithTax;
                tmp.is_all_inclusive = OI.IsAllIncl;
                tmp.is_confirmed = OI.IsConfirmed;
                tmp.is_finished = OI.IsFinished;
                tmp.option_price = OI.OptionPrice;
                tmp.order_id = OI.OrderId;
                tmp.per_item_tax = OI.PerItemTax;
                tmp.preferred_date_time = System.DateTime.Parse(OI.PreferredDatetime);
                tmp.price = OI.Price;
                tmp.quantity = OI.Quantity;
                tmp.service_id = OI.ServiceId;
                tmp.service_provider_comment = OI.Comment;
                tmp.tax = OI.Tax;

                if (NewValue)
                {
                    dbContext.Set<order_item>().Add(tmp);
                }
                dbContext.SaveChanges();

                ReturnList.Add(tmp);
            }
            return ReturnList;
        }
Example #6
0
        public Order GetOrder(int Order_ID)
        {
            List<order_item> Order_Items = new List<order_item>();
                DataSet1.Order_ItemsDataTable items = GetOrderItemsById(Order_ID);
                DataSet1.Order_DetailsDataTable details = GetOrderDetailssById(Order_ID);
                DataSet1.MenuDataTable menu = GetMenuById(Convert.ToInt32(details[0]["Rest_ID"]));
                for (int i = 0; i < items.Count; i++)
                {
                    for(int x = 0; x < menu.Count; x++){
                        if (Convert.ToInt32(menu[x]["Item_ID"]) == Convert.ToInt32(items[i]["Item_ID"]))
                        {
                            order_item item = new order_item(Convert.ToInt32(items[i][1]), (string)items[i][2], (string)menu[x][2], (string)menu[x][3]
                                , (double)menu[x][4], (string)menu[x][5], (string)menu[x][6]);
                            Order_Items.Add(item);
                        }
                    }
                }
                Order order = new Order(Convert.ToInt32(details[0][0]), Convert.ToInt32(details[0][1]), Convert.ToInt32(details[0][2]), Convert.ToString(details[0][3]),
                    (double)details[0][4], (string)details[0][5], Convert.ToInt32(details[0][6]), Order_Items);

                return order;
        }
Example #7
0
        /// <summary>
        /// Processes the notification.
        /// </summary>
        /// <param name="xmlFile">The XML file.</param>
        /// <returns>Serial number of the notification</returns>
        public static string ProcessNotification(string xmlFile)
        {
            string conn = GetConnectionString();
            StoreDataClassesDataContext db = new StoreDataClassesDataContext(conn);
            string SerialNumber            = "";
            //Read XML file
            StreamReader strReader    = new StreamReader(xmlFile);
            string       requestedXml = strReader.ReadToEnd();

            //Act on XML file
            switch (EncodeHelper.GetTopElement(requestedXml))
            {
            case "new-order-notification":
                NewOrderNotification N1 = (NewOrderNotification)EncodeHelper.Deserialize(requestedXml, typeof(NewOrderNotification));
                ///This notification tells us that Google has accepted the order
                SerialNumber = N1.serialnumber;
                Int64  OrderNumber1    = Int64.Parse(N1.googleordernumber);
                int    pos             = N1.buyershippingaddress.contactname.IndexOf(" ");
                string ShipToFirstName = N1.buyershippingaddress.contactname.Substring(0, pos);
                string ShipToLatsName  = N1.buyershippingaddress.contactname.Substring(pos + 1);
                string UserName        = N1.shoppingcart.merchantprivatedata.Any[1].InnerText;
                int    internalOrderId = int.Parse(EncodeHelper.GetElementValue(requestedXml, "MERCHANT_DATA_HIDDEN"));

                order newOrder = db.orders.Where(o => o.order_id == internalOrderId).Single <order>();

                newOrder.google_order_number = OrderNumber1;
                newOrder.order_date          = N1.timestamp;
                newOrder.order_by            = UserName;
                newOrder.sub_total           = N1.ordertotal.Value;
                newOrder.total          = N1.ordertotal.Value;
                newOrder.charged_amount = 0;
                newOrder.status         = "NEW";
                newOrder.root_id        = 1;
                //newOrder.shipping_first_name = ShipToFirstName;
                //newOrder.shipping_last_name = ShipToLatsName;
                //newOrder.shipping_address = N1.buyershippingaddress.address1;
                //newOrder.shipping_city = N1.buyershippingaddress.city;
                //newOrder.shipping_state = N1.buyershippingaddress.region;
                //newOrder.shipping_zip = N1.buyershippingaddress.postalcode;
                //newOrder.shipping_country = N1.buyerbillingaddress.countrycode;

                db.SubmitChanges();
                db.orders.DeleteAllOnSubmit(db.orders.Where(o => (o.status == "TEMP" && o.order_by == UserName)));
                db.SubmitChanges();

                foreach (Item ThisItem in N1.shoppingcart.items)
                {
                    int     itemId   = int.Parse(ThisItem.merchantprivateitemdata.Any[0].InnerText);
                    string  desc     = ThisItem.itemdescription;
                    int     quantity = ThisItem.quantity;
                    decimal price    = ThisItem.unitprice.Value;
                    bool    tangible = false;
                    if (ThisItem.digitalcontent != null)
                    {
                        tangible = true;
                    }

                    order_item newItem = new order_item();
                    newItem.item_id   = itemId;
                    newItem.order_id  = internalOrderId;
                    newItem.price     = price;
                    newItem.qty       = quantity;
                    newItem.tangible  = tangible;
                    newItem.item_desc = desc;
                    newItem.item_name = ThisItem.itemname;

                    db.order_items.InsertOnSubmit(newItem);
                    db.SubmitChanges();
                }

                break;

            case "risk-information-notification":
                RiskInformationNotification N2 = (RiskInformationNotification)EncodeHelper.Deserialize(requestedXml, typeof(RiskInformationNotification));
                // This notification tells us that Google has authorized the order and it has passed the fraud check
                SerialNumber = N2.serialnumber;
                long   googleOrderNumber = Int64.Parse(N2.googleordernumber);
                string contactName       = EncodeHelper.GetElementValue(requestedXml, "contact-name");
                string email             = EncodeHelper.GetElementValue(requestedXml, "email");
                string city     = EncodeHelper.GetElementValue(requestedXml, "city");
                int    zip      = int.Parse(EncodeHelper.GetElementValue(requestedXml, "postal-code"));
                string country  = EncodeHelper.GetElementValue(requestedXml, "country-code");
                bool   elibible = N2.riskinformation.eligibleforprotection;
                char   cvn      = char.Parse(N2.riskinformation.cvnresponse);

                if (elibible && N2.riskinformation.cvnresponse == "M")
                {
                    customer newCustomer = new customer();
                    newCustomer.google_order_number = googleOrderNumber;
                    newCustomer.eligibility         = elibible;
                    newCustomer.contact_name        = contactName;
                    newCustomer.email     = email;
                    newCustomer.address   = N2.riskinformation.billingaddress.address1;
                    newCustomer.city      = city;
                    newCustomer.zip       = zip;
                    newCustomer.country   = country;
                    newCustomer.avs       = char.Parse(N2.riskinformation.avsresponse);
                    newCustomer.cvn       = cvn;
                    newCustomer.cc_number = int.Parse(N2.riskinformation.partialccnumber);
                    newCustomer.ip        = N2.riskinformation.ipaddress;

                    db.customers.InsertOnSubmit(newCustomer);
                    db.SubmitChanges();
                }
                else
                {
                    string reason  = "You did not pass Google security check!";
                    string comment = "Please visis http://checkout.google.com/support/sell/bin/topic.py?topic=15055 for more information";
                    GCheckout.OrderProcessing.CancelOrderRequest cancelReq = new GCheckout.OrderProcessing.CancelOrderRequest(N2.googleordernumber, reason, comment);
                    cancelReq.Send();
                }

                break;

            case "order-state-change-notification":
                OrderStateChangeNotification N3 = (OrderStateChangeNotification)EncodeHelper.Deserialize(requestedXml, typeof(OrderStateChangeNotification));
                // The order has changed either financial or fulfillment state in Google's system.
                SerialNumber = N3.serialnumber;
                long   googleOrderNumber1   = Int64.Parse(N3.googleordernumber);
                string newFinanceState      = N3.newfinancialorderstate.ToString();
                string newFulfillmentState  = N3.newfulfillmentorderstate.ToString();
                string prevFinanceState     = N3.previousfinancialorderstate.ToString();
                string prevFulfillmentState = N3.previousfulfillmentorderstate.ToString();

                order thisOrder1 = (from or in db.orders where or.google_order_number == googleOrderNumber1 select or).Single <order>();
                //if (newFinanceState == "CHARGEABLE")
                //{
                //    GCheckout.OrderProcessing.ChargeOrderRequest chargeReq = new GCheckout.OrderProcessing.ChargeOrderRequest(N3.googleordernumber);
                //    chargeReq.Send();
                //}
                thisOrder1.status = newFinanceState;
                if (newFulfillmentState == "WILL_NOT_DELIVER")
                {
                    thisOrder1.shipping_status = "CANCELLED";
                }
                else
                {
                    thisOrder1.shipping_status = newFulfillmentState;
                }
                db.SubmitChanges();
                break;

            case "charge-amount-notification":
                ChargeAmountNotification N4 = (ChargeAmountNotification)EncodeHelper.Deserialize(requestedXml, typeof(ChargeAmountNotification));
                // Google has successfully charged the customer's credit card.
                SerialNumber = N4.serialnumber;
                long    googleOrderNumber2 = Int64.Parse(N4.googleordernumber);
                decimal chargedAmount      = N4.latestchargeamount.Value;

                order thisOrder2 = (from or in db.orders where or.google_order_number == googleOrderNumber2 select or).Single <order>();
                thisOrder2.charged_amount += chargedAmount;
                thisOrder2.sub_total      -= chargedAmount;
                db.SubmitChanges();

                break;

            case "refund-amount-notification":
                RefundAmountNotification N5 = (RefundAmountNotification)EncodeHelper.Deserialize(requestedXml, typeof(RefundAmountNotification));
                // Google has successfully refunded the customer's credit card.
                SerialNumber = N5.serialnumber;
                long    googleOrderNumber3 = Int64.Parse(N5.googleordernumber);
                decimal refundedAmount     = N5.latestrefundamount.Value;

                order thisOrder3 = (from or in db.orders where or.google_order_number == googleOrderNumber3 select or).Single <order>();
                thisOrder3.status          = "REFUNDED";
                thisOrder3.charged_amount -= refundedAmount;
                db.SubmitChanges();

                break;

            case "chargeback-amount-notification":
                ChargebackAmountNotification N6 = (ChargebackAmountNotification)EncodeHelper.Deserialize(requestedXml, typeof(ChargebackAmountNotification));
                // A customer initiated a chargeback with his credit card company to get her money back.
                SerialNumber = N6.serialnumber;
                long    googleOrderNumber4 = Int64.Parse(N6.googleordernumber);
                decimal chargebackAmount   = N6.latestchargebackamount.Value;

                order thisOrder4 = (from or in db.orders where or.google_order_number == googleOrderNumber4 select or).Single <order>();
                thisOrder4.status = "CHARGEBACK";
                db.SubmitChanges();

                break;

            default:
                break;
            }

            strReader.Close();
            strReader.Dispose();
            return(SerialNumber);
        }
Example #8
0
 public ActionResult Edit(order_item orderItem)
 {
     BookStoreDB.Entry(orderItem).State = System.Data.Entity.EntityState.Modified;
     BookStoreDB.SaveChanges();
     return(RedirectToAction("Index"));
 }