Problem writing data from textbox to new field in Order table in NopCommerce 2.65

I am trying to write data from a textbox as below to a newly created field in the Order table
of a sql server database. I am using NopCommerce 2.65
I am at the moment pullly my hair out trying to find an answer on the internet.
Nop.Web/Themes/CorpWear2/Views/ShoppingCart/OrderSummary.cshtml
Thanks in advance for any help given.
<textarea cols="20" rows="2" id="AdditionalInformation" name="AdditionalInformation">
@Session["AdditionalInformation"]</textarea>

Open in new window

The following code is what I have achieved by reading data from the Field and displaying
it on the OrderSummary.cshtml page.
1.Created Field: OrderEnquiry in Order Table
2.Nop.Core.Domain.Orders.Order.cs
#region Properties
public virtual string OrderEnquiry { get; set; }
3.Nop.Data.Mapping.Orders.OrderMap.cs
this.Property(o => o.OrderEnquiry).HasMaxLength(255).IsOptional();
4.Nop.Web.Themes.CorpWear2.Views.Order.Details.cs
http://localhost:2619/orderdetails/7697
@Html.Widget("orderdetails_page_bottom")
<div class = "order-enquiry">
OrderEnquiry:@Html.Raw(Model.OrderEnquiry)#
</div>
5.Nop.Web.Controllers.OrderController.cs
#region Utilities
[NonAction]
protected OrderDetailsModel PrepareOrderDetailsModel(Order order)
{
// Alteration
model.OrderEnquiry = order.OrderEnquiry;

Open in new window

homeshopperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

homeshopperAuthor Commented:
I have made the following changes to the textbox in OrderSummary page,
but still unable to get the field OrderEnquiry in Order Table to update with data from the textbox.
Thanks in advance for any help given.
6.Nop.Web.Modules.ShoppingCart.ShoppingCartModule.cs
public string OrderEnquiry { get; set; }
7.Nop.Web.Themes.CorpWear2.Views.ShoppingCart.OrderSummary.cs
AddInfo:@Html.TextAreaFor(model => model.OrderEnquiry, new { style = "width:465px; height:45px" })#

Open in new window

0
homeshopperAuthor Commented:
I have an update on the code I am using, but still have a problem to update new field OrderEnquiry in Order Table from TextBox. The code I have is listed below: Thanks in advance for any help given.
Confirm.cshtml
@using (Html.BeginRouteForm("CheckoutConfirm", "Confirm", FormMethod.Post, new { id = "confirm-order-form" }))
    {
                if (!String.IsNullOrEmpty(Model.MinOrderTotalWarning))
                {
                    @Model.MinOrderTotalWarning
                }
                else
                {              
                    string name = Request.Form["confirm-order-form"];
                    <label>Post some text</label>
                    @Html.TextBoxFor(m => Model.OrderEnquiry)
                    ViewContext.Writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                    <a href="Confirm" class="Button3">Update</a>
                    <input type="submit" value="PostSomeText" class="Button3" />    
                    <br />
                    ViewContext.Writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                    ViewContext.Writer.Write("[" + name + "]");       
                }            
    }

Open in new window

CheckoutController.cs
[HttpPost]
    public ActionResult Confirm(string myString)
    {
        //validation
        var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
        if (cart.Count == 0)
            return RedirectToRoute("ShoppingCart");
        if (UseOnePageCheckout())
            return RedirectToRoute("CheckoutOnePage");
        if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
            return new HttpUnauthorizedResult();
        //model
        var model = PrepareConfirmOrderModel(cart);
        return View(model);
    }
    [HttpPost, ActionName("Confirm")]
    [ValidateInput(false)]
    public ActionResult ConfirmOrder()
    {
        //validation
        var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
        if (cart.Count == 0)
            return RedirectToRoute("ShoppingCart");
        if (UseOnePageCheckout())
            return RedirectToRoute("CheckoutOnePage");
        if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
            return new HttpUnauthorizedResult();
        //model
        var model = new CheckoutConfirmModel();
        try
        {
            var processPaymentRequest = _httpContext.Session["OrderPaymentInfo"] as ProcessPaymentRequest;
            if (processPaymentRequest == null)
            {
                //Check whether payment workflow is required
                if (IsPaymentWorkflowRequired(cart))
                    return RedirectToRoute("CheckoutPaymentInfo");
                else
                    processPaymentRequest = new ProcessPaymentRequest();
            }            
            //prevent 2 orders being placed within an X seconds time frame
            if (!IsMinimumOrderPlacementIntervalValid(_workContext.CurrentCustomer))
                throw new Exception(_localizationService.GetResource("Checkout.MinOrderPlacementInterval"));
            //place order
            processPaymentRequest.CustomerId = _workContext.CurrentCustomer.Id;
            processPaymentRequest.PaymentMethodSystemName = _workContext.CurrentCustomer.SelectedPaymentMethodSystemName;
            var placeOrderResult = _orderProcessingService.PlaceOrder(processPaymentRequest);
            if (placeOrderResult.Success)
            {
                _httpContext.Session["OrderPaymentInfo"] = null;
                var postProcessPaymentRequest = new PostProcessPaymentRequest()
                {
                    Order = placeOrderResult.PlacedOrder
                };
                _paymentService.PostProcessPayment(postProcessPaymentRequest);
                if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
                {
                    //redirection or POST has been done in PostProcessPayment
                    return Content("Redirected");
                }
                else
                {
                    //if no redirection has been done (to a third-party payment page)
                    //theoretically it's not possible
                    return RedirectToRoute("CheckoutConfirm");
                }
            }
            else
            {
                foreach (var error in placeOrderResult.Errors)
                    model.Warnings.Add(error);
            }
        }
        catch (Exception exc)
        {
            _logger.Warning(exc.Message, exc);
            model.Warnings.Add(exc.Message);
        }

        //If we got this far, something failed, redisplay form
        return View(model);
    }

Open in new window

0
homeshopperAuthor Commented:
I am still having a problem & require some help,
updating the OrderEnquiry field in the Order table.
I put a break point just after public ActionResult ConfirmOrder(string myString)
but it does not stop the process, it still writes a record to the table without OrderEnquiry.
Thanks in advance.

Nop.Web.Themes.CorpWear2.Views.Checkout.Confirm.cs
@using (Html.BeginRouteForm("CheckoutConfirm", FormMethod.Post, new { id = 
"confirm-order-form" }))
        {
            @Html.Widget("checkout_confirm_top")                                 
                    if (!String.IsNullOrEmpty(Model.MinOrderTotalWarning))
                    {
                        @Model.MinOrderTotalWarning
                    }
                    else
                    {
                        string name = Request.Form["confirm-order-form"];
                        <label>Post some text</label>
                        @Html.TextBoxFor(m => Model.OrderEnquiry)
                        
ViewContext.Writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                        <input type="submit" name="nextstep" 
value="@T("Checkout.ConfirmButton")" class="Button3" />
                        <a href="Confirm" class="Button3">Update</a>
                        <input type="submit" value="PostSomeText" class="Button3" />    
                        <br />
                        Session["nCount"] = nCount + 1;
                        
ViewContext.Writer.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;");
                        ViewContext.Writer.Write("[" + Session["nCount"] + "]" + "[" + 
Model.OrderEnquiry + "]");
                    }      
            @Html.Widget("checkout_confirm_bottom")
        }

Open in new window

Nop.Web.Controllers.CheckoutController.cs
[HttpPost, ActionName("Confirm")]
        [ValidateInput(false)]
        public ActionResult ConfirmOrder(string myString)
        {
            //validation
            var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => 
sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
            if (cart.Count == 0)
                return RedirectToRoute("ShoppingCart");
            if (UseOnePageCheckout())
                return RedirectToRoute("CheckoutOnePage");
            if ((_workContext.CurrentCustomer.IsGuest() && 
!_orderSettings.AnonymousCheckoutAllowed))
                return new HttpUnauthorizedResult();
            //model
            var model = new CheckoutConfirmModel();
            try
            {
                var processPaymentRequest = _httpContext.Session["OrderPaymentInfo"] as 
ProcessPaymentRequest;
                if (processPaymentRequest == null)
                {
                    //Check whether payment workflow is required
                    if (IsPaymentWorkflowRequired(cart))
                        return RedirectToRoute("CheckoutPaymentInfo");
                    else
                        processPaymentRequest = new ProcessPaymentRequest();
                }             
                //prevent 2 orders being placed within an X seconds time frame
                if (!IsMinimumOrderPlacementIntervalValid(_workContext.CurrentCustomer))
                    throw new 
Exception(_localizationService.GetResource("Checkout.MinOrderPlacementInterval"));
                //place order
                processPaymentRequest.CustomerId = _workContext.CurrentCustomer.Id;
                processPaymentRequest.PaymentMethodSystemName = 
_workContext.CurrentCustomer.SelectedPaymentMethodSystemName;
                var placeOrderResult = 
_orderProcessingService.PlaceOrder(processPaymentRequest);
                if (placeOrderResult.Success)
                {
                    _httpContext.Session["OrderPaymentInfo"] = null;
                    var postProcessPaymentRequest = new PostProcessPaymentRequest()
                    {
                        Order = placeOrderResult.PlacedOrder
                    };
                    _paymentService.PostProcessPayment(postProcessPaymentRequest);

                    if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
                    {
                        //redirection or POST has been done in PostProcessPayment
                        return Content("Redirected");
                    }
                    else
                    {
                        //if no redirection has been done (to a third-party payment page)
                        //theoretically it's not possible
                        //return RedirectToRoute("CheckoutCompleted");
                    }
                }
                else
                {
                    foreach (var error in placeOrderResult.Errors)
                        model.Warnings.Add(error);
                }
            }
            catch (Exception exc)
            {
                _logger.Warning(exc.Message, exc);
                model.Warnings.Add(exc.Message);
            }
            //If we got this far, something failed, redisplay form
            return View(model);
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
homeshopperAuthor Commented:
Still have a problem writting data to field OrderEnquiry in Order table of database,
 I would appreciate any help given on this.
 However, in the meantime I have been able to read from the field by doing the following:
1) Nop.Web.Controllers.OrderController.cs
 model.OrderEnquiry = order.OrderEnquiry;

 [NonAction]
 protected OrderDetailsModel PrepareOrderDetailsModel(Order order)
 {
 model.OrderEnquiry = order.OrderEnquiry;

 2) Nop.Data.Mapping.Orders.OrderMap.cs
 this.Property(o => o.OrderEnquiry).HasMaxLength(3000).IsOptional();

 3) Nop.Core.Domain.Orders.Order.cs
 public virtual string OrderEnquiry { get; set; }

 4) Nop.Web.Models.Order.OrderDetailsModel.cs
 public string OrderEnquiry { get; set; }

 5) Nop.Web>controllers.CheckoutController.cs
 [NonAction]
 protected CheckoutConfirmModel PrepareConfirmOrderModel(IList<ShoppingCartItem> cart)
 {
 Session["AdditionalInformation"] = model.OrderEnquiry;

 [HttpPost, ActionName("Confirm")]
 [ValidateInput(false)]
 public ActionResult ConfirmOrder(string OrderEnquiry, int id)
 {
 Session["AdditionalInformation"] = model.OrderEnquiry;

 6) Nop.Web.Models.Checkout.CheckoutCompletedModel.cs
 public string OrderEnquiry { get; set; }

 7) Nop.Web.Models.Checkout.CheckoutConfirmModel.cs
 public string OrderEnquiry { get; set; }

 8) Nop.Web.Models.ShoppingCart.ShoppingCartModel.cs
 public string OrderEnquiry { get; set; }

 9) Views.Checkout.Completed.cshtml
 <div class = "order-enquiry">
 OrderEnquiry:@Html.Raw(Model.OrderEnquiry)#<br />
 AdditionalInfo:@Session["AdditionalInformation"]#
 </div>

Open in new window

In regard to writing data to the OrderEnquiry Field in the Order table, I have the following code:
Views.Checkout.COnfirm.cshtml
 @using (Html.BeginRouteForm("CheckoutConfirm", "Confirm", FormMethod.Post, new { id = "confirm-order-form" }))
 {
     <div id="fldset" style=" position:relative; background-color:White; left:10px; width:680px;">
     <br />
     <fieldset>
         <legend>Information</legend>
         <p></p>
         <div class="editor-label">
             @Html.LabelFor(model => model.OrderEnquiry)
         </div>
         <div class="editor-field">
             @*Based on your object to change the Id to the Corresponding property name*@
             @Html.HiddenFor(Model => Model.id)
             @Html.TextAreaFor(Model => Model.OrderEnquiry, new { style = "width:465px; height:45px" })
            <input type="submit" name="nextstep" value="@T("Checkout.ConfirmButton")" class="Button3" /><br />
            @*
             @Html.ValidationMessageFor(model => model.OrderEnquiry)
            *@
            AdditionInfo:@Session["AdditionalInformation"]#
         </div>
     </fieldset>
     </div>
 }

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.