Exemple #1
0
        /// <summary>
        /// Populates defaults and opens edit form to add new record
        /// GET: /Admin/ShoppingCartOrder/Create
        /// </summary>
        public ActionResult Create()
        {
            Breadcrumbs.Current.AddBreadcrumb(3, "Add Shopping Cart Order");
            var record = new Models.ShoppingCartOrder();

            // any default values can be set here or in partial class ShoppingCartOrder.InitDefaults()
            return(View("ShoppingCartOrderEdit", record));
        }
Exemple #2
0
        protected ActionResult ProcessForm(Models.ShoppingCartOrder record)
        {
            try {
                record.UpdateFromRequest();
                Validate(record);
                if (ModelState.IsValid)
                {
                    Save(record, record.IsNewRecord);
                    Web.InfoMessage = "Shopping Cart Order " + record.GetName() + " saved.";
                }
            } catch (UserErrorException e) {
                ModelState.AddModelError("Record", e.Message);
            }

            if (!ModelState.IsValid)
            {
                // invalid so redisplay form with validation message(s)
                return(View("ShoppingCartOrderEdit", record));
            }
            else if (Web.Request["SaveAndRefreshButton"] != null)
            {
                return(RedirectToEdit(record.ID));
            }
            else if (Web.Request["DuplicateButton"] != null)
            {
                var newRecord = new Models.ShoppingCartOrder();
                newRecord.UpdateFrom(record);
                newRecord.Save();
                Web.InfoMessage = "Copy of Shopping Cart Order " + record.GetName() + " created. You are now editing the new copy.";
                return(RedirectToEdit(newRecord.ID));
            }
            else
            {
                return(RedirectToReturnPage());
            }
        }
Exemple #3
0
        public ActionResult PlaceOrder(string encryptedUserToken, bool isCostEnquiry, string Notes, string coref)
        {
            var PersonID = Crypto.DecryptID(encryptedUserToken);
            var per      = Crypto.DecryptID(encryptedUserToken);

            if (per == -1)
            {
                throw new Exception("person invalid");
            }


            string basketContents = "";
            //result+="person["+PersonID+"]";

            //create order email

            var person = Models.Person.LoadID(PersonID);
            var order  = new Models.ShoppingCartOrder();

            order.AddNew();
            order.DateOrdered            = DateTime.Now;
            order.OrderRef               = Models.ShoppingCart.GenerateRef();
            order.PersonID               = PersonID;
            order.Email                  = person.Email;
            order.FirstName              = person.FirstName;
            order.LastName               = person.LastName;
            order.IsCostEnquiry          = isCostEnquiry;
            order.CustomerOrderReference = coref;
            order.Notes                  = Notes;
            order.Save();
            //decimal erpID = -1;
            //string nimDataInSQLConn = BewebData.GetConnectionString("NimbleCartSQLConnection");
            //if (Util.GetSettingBool("SaveCartToERP") && Util.IsBewebOffice) {
            //  erpID = GetCartHeaderERPID(order, nimDataInSQLConn);

            //  SaveCartHeaderToERP(person, order, erpID, isCostEnquiry, nimDataInSQLConn);
            //}

            basketContents += "<table class=\"result\" style=\"width:100%\" cellspacing=\"0\" border=\"0\" cellspacing=\"0\">";
            basketContents += "<tr class=\"header\"><td>VehID</td><td>Part</td><td>QTY</td></tr>";
            var status      = "Shopping";
            var itemsInCart = Models.ShoppingCartList.Load(new Sql("where personid=", PersonID, " and Status=", status.Sqlize_Text(), " and isnull(isdeleted,0)=0 order by dateadded"));

            if (itemsInCart.Count > 0)
            {
                foreach (var cartItem in itemsInCart)
                {
                    string removelink = "<a href=\"\" onclick=\"return handleCartRemove(this,'" + Crypto.EncryptID(cartItem.ID) + "','" + encryptedUserToken.JsEncode() + "')\"><img width=\"32\" src=\"" + Web.Root + "images/cart-remove.gif\"></a>";
                    basketContents += "<tr><td>" + cartItem.PartDescription + "</td><td>" + cartItem.Quantity + "</td></tr>";
                    cartItem.Status = "Ordered";
                    cartItem.ShoppingCartOrderID = order.ID;
                    cartItem.Save();

                    //SaveCartLineToERP(nimDataInSQLConn, erpID, cartItem);
                }
            }
            else
            {
                basketContents += "<tr><td colspan=\"4\">Nothing in your cart</td></tr>";
            }
            basketContents += "<tr><td>Notes</td><td colspan=\"3\">" + Notes.HtmlEncode() + "</td></tr>";
            basketContents += "</table>";
            //update the deleted items status that is currently set to shopping, change to archived
            new Sql("update ShoppingCart set status=", ("Archived").Sqlize_Text(), ", ShoppingCartOrderID=", order.ID, "where personid=", PersonID, " and Status=", status.Sqlize_Text(), " and isnull(isdeleted,0)=1 ").Execute();

            //send email to admin
            //basketContents = Savvy.Site.SendOrderEmail(order, person, isCostEnquiry, basketContents);


            return(Content(basketContents, "text/html"));
        }
Exemple #4
0
 private void Save(Models.ShoppingCartOrder record, bool isNew)
 {
     // add any code to update other fields/tables here
     record.Save();
 }
Exemple #5
0
 private void Validate(Models.ShoppingCartOrder record)
 {
     // add any code to check for validity
     //ModelState.AddModelError("Record", "Suchandsuch cannot be whatever.");
 }