Ejemplo n.º 1
0
        public async Task<ActionResult> Complete(int id = 0) {
            HttpContext ctx = System.Web.HttpContext.Current;
            Customer customer = new Customer();
            ViewBag.timezone = UDF.GetTimeZone(ctx);

            var pcats = CURTAPI.GetParentCategoriesAsync();
            await Task.WhenAll(new Task[] { pcats });
            ViewBag.parent_cats = await pcats;

            // Retrieve Customer from Sessions/Cookie
            customer.GetFromStorage(ctx);
            Cart order = new Cart().Get(id);

            order.BindAddresses();
            Payment payment = order.getPayment();

            ViewBag.order = order;
            ViewBag.payment = payment;

            return View();
        }
        public ActionResult Complete(int id = 0)
        {
            Customer customer = new Customer();

            // Retrieve Customer from Sessions/Cookie
            customer.GetFromStorage();
            Cart order = new Cart().Get(id);

            if (!customer.LoggedIn() || order.cust_id != customer.ID) {
                return RedirectToAction("Index", "Authenticate");
            }

            order.BindAddresses();
            Payment payment = order.getPayment();

            ViewBag.order = order;
            ViewBag.payment = payment;

            return View();
        }
Ejemplo n.º 3
0
        internal void CreatePurchaseOrder(int id = 0) {
                try {
                    Settings settings = new Settings();
                    Cart order = new Cart().Get(id);
                    Payment payment = order.getPayment();
                    if (order.CartItems.Count > 0) {
                        Customer cust = new Customer { ID = order.cust_id };
                        cust.Get();
                        order.BindAddresses();
                        string ponumber = settings.Get("EDIPOPreface") + order.payment_id.ToString();
                        CloudBlockBlob blob = null;
                        string edicontent = "";
                        int linecount = 1;
                        // linecount is just for the PO section and doesn't include the head or tail
                        // next two lines are head
                        edicontent += "ISA*00*          *00*          *12*" + settings.Get("EDIPhone") + "     *01*809988975      *" + String.Format("{0:yyMMdd}*{0:hhmm}", payment.created) + "*U*00401*" + order.payment_id.ToString("000000000") + "*0*P*>~" + Environment.NewLine;
                        edicontent += "GS*PO*" + settings.Get("EDIPhone") + "*809988975*" + String.Format("{0:yyyyMMdd}*{0:hhmm}", payment.created) + "*" + order.payment_id.ToString("000000000") + "*X*004010~" + Environment.NewLine;
                        // begin PO section
                        edicontent += "ST*850*000000001~" + Environment.NewLine;
                        linecount++;
                        edicontent += "BEG*00*DS*" + ponumber + "**" + String.Format("{0:yyyyMMdd}", payment.created) + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "CUR*BT*USD~" + Environment.NewLine;
                        linecount++;
                        edicontent += "REF*CO*" + ponumber + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "REF*IA*" + settings.Get("CURTAccount") + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "DTM*002*" + String.Format("{0:yyyyMMdd}", payment.created) + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N1*ST*" + order.Shipping.first + " " + order.Shipping.last + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N3*" + order.Shipping.street1 + ((order.Shipping.street2 != null && order.Shipping.street2 != "") ? "*" + order.Shipping.street2 : "") + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N4*" + order.Shipping.city + "*" + order.Shipping.State1.abbr + "*" + order.Shipping.postal_code + "*" + order.Shipping.State1.Country.longAbbr + "~" + Environment.NewLine;
                        if (!String.IsNullOrEmpty(cust.phone)) {
                            linecount++;
                            edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*TE*" + cust.phone + "~" + Environment.NewLine;
                        }
                        linecount++;
                        edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*EM*" + cust.email + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "TD5**2*FDEG*P*" + order.shipping_type + "~" + Environment.NewLine;
                        for (int i = 0; i < order.CartItems.Count; i++) {
                            linecount++;
                            edicontent += "PO1*" + (i + 1).ToString("000") + "*" + order.CartItems[i].quantity + "*EA***BP*" + order.CartItems[i].partID + "*VP*" + order.CartItems[i].partID + "*UP*" + order.CartItems[i].upc + "~" + Environment.NewLine;
                            linecount++;
                            edicontent += "CTP*PUR*" + String.Format("{0:0.00}", order.CartItems[i].price) + "~" + Environment.NewLine;
                            linecount++;
                            edicontent += "PID*F*08***" + order.CartItems[i].shortDesc + "~" + Environment.NewLine;
                        }
                        linecount++;
                        edicontent += "CTT*" + order.CartItems.Count + "*" + order.getCount() + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "SE*" + linecount + "*000000001~" + Environment.NewLine;
                        // end PO section
                        // begin Tail section
                        edicontent += "GE*1*" + order.payment_id.ToString("000000000") + "~" + Environment.NewLine;
                        edicontent += "IEA*1*" + order.payment_id.ToString("000000000") + "~";

                        // write file
                        DiscountBlobContainer blobcontainer = BlobManagement.GetContainer("edi");
                        BlobContainerPermissions perms = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob };
                        blobcontainer.Container.SetPermissions(perms);
                        string filename = "PO" + String.Format("{0:yyyyMMdd}_{0:HHmmss}", payment.created) + ".txt";
                        blob = blobcontainer.Container.GetBlockBlobReference("out\\" + filename);
                        byte[] edibytes = Encoding.ASCII.GetBytes(edicontent);
                        MemoryStream edistream = new MemoryStream(edibytes);
                        blob.UploadFromStream(edistream);
                        OrderEDI orderedi = new OrderEDI {
                            orderID = order.ID,
                            editext = edicontent,
                            filename = filename,
                            dateAcknowledged = null,
                        };
                        orderedi.Save();
                    }
                } catch { };
        }
Ejemplo n.º 4
0
        internal void CreatePurchaseOrder(int id = 0)
        {
            if (!(HttpContext.Current.Request.Url.Host.Contains("127.0.0") || HttpContext.Current.Request.Url.Host.Contains("localhost"))) {
                try {
                    Settings settings = new Settings();
                    Cart order = new Cart().Get(id);
                    if (order.CartItems.Count > 0) {
                        Customer cust = new Customer { ID = order.cust_id };
                        cust.Get();
                        order.BindAddresses();
                        CloudBlob blob = null;
                        string edicontent = "";
                        int linecount = 1;
                        // linecount is just for the PO section and doesn't include the head or tail
                        // next two lines are head
                        edicontent += "ISA*00*          *00*          *12*" + settings.Get("EDIPhone") + "     *01*809988975      *" + String.Format("{0:yyMMdd}*{0:hhmm}", DateTime.Now) + "*U*00401*" + order.payment_id.ToString("000000000") + "*0*P*>~" + Environment.NewLine;
                        edicontent += "GS*PO*" + settings.Get("EDIPhone") + "*809988975*" + String.Format("{0:yyyyMMdd}*{0:hhmm}", DateTime.Now) + "*" + order.payment_id.ToString("000000000") + "*X*004010~" + Environment.NewLine;
                        // begin PO section
                        edicontent += "ST*850*" + order.payment_id + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "BEG*00*DS*" + order.payment_id + "**" + String.Format("{0:yyyyMMdd}", order.getPayment().created) + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "CUR*BT*USD~" + Environment.NewLine;
                        linecount++;
                        edicontent += "REF*CO*" + order.payment_id + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "REF*IA*" + settings.Get("CURTAccount") + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "DTM*002*" + String.Format("{0:yyyyMMdd}", order.getPayment().created) + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N1*ST*" + order.Shipping.first + " " + order.Shipping.last + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N3*" + order.Shipping.street1 + ((order.Shipping.street2 != null && order.Shipping.street2 != "") ? "*" + order.Shipping.street2 : "") + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N4*" + order.Shipping.city + "*" + order.Shipping.State1.abbr + "*" + order.Shipping.postal_code + "*" + order.Shipping.State1.Country.longAbbr + "~" + Environment.NewLine;
                        if (!String.IsNullOrEmpty(cust.phone)) {
                            linecount++;
                            edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*TE*" + cust.phone + "~" + Environment.NewLine;
                        }
                        linecount++;
                        edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*EM*" + cust.email + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "TD5**2*FDEG*P*" + order.shipping_type + "~" + Environment.NewLine;
                        for (int i = 0; i < order.CartItems.Count; i++) {
                            linecount++;
                            edicontent += "PO1*" + (i + 1).ToString("000") + "*" + order.CartItems[i].quantity + "*EA***BP*" + order.CartItems[i].partID + "*VP*" + order.CartItems[i].partID + "*UP*" + order.CartItems[i].upc + "~" + Environment.NewLine;
                            linecount++;
                            edicontent += "CTP*PUR*" + String.Format("{0:0.00}", order.CartItems[i].price) + "~" + Environment.NewLine;
                            linecount++;
                            edicontent += "PID*F*08***" + order.CartItems[i].shortDesc + "~" + Environment.NewLine;
                        }
                        linecount++;
                        edicontent += "CTT*" + order.CartItems.Count + "*" + order.getCount() + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "SE*" + linecount + "*" + order.payment_id + "~" + Environment.NewLine;
                        // end PO section
                        // begin Tail section
                        edicontent += "GE*1*" + order.payment_id.ToString("000000000") + "~" + Environment.NewLine;
                        edicontent += "IEA*1*" + order.payment_id.ToString("000000000") + "~";

                        // write file
                        DiscountBlobContainer blobcontainer = BlobManagement.GetContainer("edi");
                        BlobContainerPermissions perms = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob };
                        blobcontainer.Container.SetPermissions(perms);
                        blob = blobcontainer.Container.GetBlobReference(string.Format("out\\PO{0}_{1}.txt", String.Format("{0:yyyyMMdd}", DateTime.Now), String.Format("{0:HHmmss}", DateTime.Now)));
                        blob.UploadText(edicontent);
                    }
                } catch { };
            }
        }