2

I'm quite new to ASP.Net MVC and what I'm trying to do is to find a simpler way of adding multiple Orders to my Delivery table. At the moment, the only way I can add Orders to my Delivery table is through my Order Edit View. Which is extremely time-consuming because of the multiple clicking I have to go through.

So after I create my Delivery, I get directed to my Delivery Detail View where I can see my Delivery and the Orders linked to that Delivery, but the only way I can add Orders to the Delivery is if I go to the Edit Order View where I link delivery_id to the Order there.

What I did for now was that I added a button on my Delivery Details View that takes me to the Order Index View with all my Orders, and I then set the delivery_id by clicking on Edit Order for each individual Order I want part of that Delivery, and then doing the linkage in there. This is basically done one by one.

I want to be able to add multiple Orders to specific Delivery without having to go through that process.

If anyone can suggest a simpler solution for this, I'll Greatly appreciate it!

Delivery Controller:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using HealthHabitat.DAL;
using HealthHabitat.Models;

namespace HealthHabitat.Controllers
{
    public class DeliveryController : Controller
    {
        private HealthContext db = new HealthContext();

        // GET: Delivery
        public ActionResult Index()
        {
            var Deliverys = db.Deliverys.Include(o => o.Driver);
            return View(db.Deliverys.ToList());
        }

        // GET: Delivery/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Delivery delivery = db.Deliverys.Find(id);
            if (delivery == null)
            {
                return HttpNotFound();
            }
            return View(delivery);
        }

        // GET: Delivery/Create
        public ActionResult Create()
        {
            var delivery = new Delivery
            {
                Dispatched_Time = DateTime.Now,
                Dispatched_Date = DateTime.Now,

            };
            ViewBag.DriverID = new SelectList(db.Drivers, "DriverID", "First_Name");
            return View(delivery);
        }

        // POST: Delivery/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "DeliveryID,DriverID,Status,Comment,Dispatched_Date,Dispatched_Time,Delivered_Date,Delivered_Time,Delayed_Date,Delayed_Time")] Delivery delivery)
        {
            if (ModelState.IsValid)
            {
                db.Deliverys.Add(delivery);
                db.SaveChanges();
                return RedirectToAction("Details", new { id = delivery.DeliveryID });
            }

            ViewBag.DriverID = new SelectList(db.Drivers, "DriverID", "First_Name", delivery.DriverID);
            return View(delivery);
        }

        // GET: Delivery/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Delivery delivery = db.Deliverys.Find(id);
            if (delivery == null)
            {
                return HttpNotFound();
            }
            ViewBag.DriverID = new SelectList(db.Drivers, "DriverID", "First_Name", delivery.DriverID);
            return View(delivery);
        }

        // POST: Delivery/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "DeliveryID,DriverID,Status,Comment,Dispatched_Date,Dispatched_Time,Delivered_Date,Delivered_Time,Delayed_Date,Delayed_Time")] Delivery delivery)
        {
            if (ModelState.IsValid)
            {
                db.Entry(delivery).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Details", new { id = delivery.DeliveryID });
            }
            ViewBag.DriverID = new SelectList(db.Drivers, "DriverID", "First_Name", delivery.DriverID);
            return View(delivery);
        }

        // GET: Delivery/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Delivery delivery = db.Deliverys.Find(id);
            if (delivery == null)
            {
                return HttpNotFound();
            }
            return View(delivery);
        }

        // POST: Delivery/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Delivery delivery = db.Deliverys.Find(id);
            db.Deliverys.Remove(delivery);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

Delivery Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace HealthHabitat.Models
{
    public enum Status
    {
       Dispatched, Delayed, Delivered
    }
    public class Delivery
    {

        public int DeliveryID { get; set; }
        [Display(Name = "Driver")]
        public int DriverID { get; set; }
        public Status Status { get; set; }

        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Comment { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Display(Name = "Date Dispatched")]
        public DateTime Dispatched_Date { get; set; }

        [DataType(DataType.Time)]
        [DisplayFormat(DataFormatString = "{0:HH:mm}", ApplyFormatInEditMode = true)]
        [Display(Name = "Time Dispatched")]
        public DateTime Dispatched_Time { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Display(Name = "Date Delivered")]
        public DateTime? Delivered_Date { get; set; }

        [DataType(DataType.Time)]
        [DisplayFormat(DataFormatString = "{0:HH:mm}", ApplyFormatInEditMode = true)]
        [Display(Name = "Time Delivered")]
        public DateTime? Delivered_Time { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Display(Name = "Date Delayed")]
        public DateTime? Delayed_Date { get; set; }

        [DataType(DataType.Time)]
        [DisplayFormat(DataFormatString = "{0:HH:mm}", ApplyFormatInEditMode = true)]
        [Display(Name = "Time Delayed")]
        public DateTime? Delayed_Time { get; set; }



        public virtual Driver Driver { get; set; }
        public virtual ICollection<Order> Orders { get; set; }
    }
}

Delivery Details View:

@model HealthHabitat.Models.Delivery

@{
    ViewBag.Title = "View Delivery Details";
}



<div>
    <h4>Delivery</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.DriverID)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Driver.Last_Name)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Status)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Status)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Comment)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Comment)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Dispatched_Date)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Dispatched_Date)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Dispatched_Time)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Dispatched_Time)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Delivered_Date)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Delivered_Date)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Delivered_Time)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Delivered_Time)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Delayed_Date)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Delayed_Date)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Delayed_Time)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Delayed_Time)
        </dd>

    </dl>
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                Order Details
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>Order Number </th>
                                <th>Order Date </th>
                                <th>Order Time</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.Orders)
                            {
                                <tr>
                                    <td style="width:auto">
                                        @Html.DisplayFor(m => item.OrderID)
                                    </td>
                                    <td style="width:auto">
                                        @Html.DisplayFor(m => item.Date)
                                    </td>
                                    <td style="width:auto">
                                        @Html.DisplayFor(m => item.Time)
                                    </td>
                                    @*<td style="width:auto">
                                        @Html.ActionLink("View Order", "Details", "Order", new { ID = item.DeliveryID }, null)
                                    </td>
                                    <td style="width:auto">
                                        @Html.ActionLink("Remove Order", "Delete", "Order", new { ID = item.DeliveryID }, null)
                                    </td>*@
                                </tr>
                            }
                        </tbody>
                    </table>
                    <p>
                        <a href="@Url.Action("Index", "Order", new { id = Model.DeliveryID }, null)" class="btn btn-success" style="float:right"> Add Orders</a>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.DeliveryID }) |
    <a href="~/Delivery/Index" class="btn btn-primary">Back</a>
</p>

Order Controller:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using HealthHabitat.DAL;
using HealthHabitat.Models;

namespace HealthHabitat.Controllers
{
    public class OrderController : Controller
    {
        private HealthContext db = new HealthContext();

        // GET: Order
        public ActionResult Index()
        {
            var orders = db.Orders.Include(o => o.Staff).Include(o => o.Hospital).Include(o => o.Delivery);
            return View(orders.ToList());
        }

        // GET: Order/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Order order = db.Orders.Where(o => o.OrderID == id).Include("OrderItems").FirstOrDefault();
            if (order == null)
            {
                return HttpNotFound();
            }
            return View(order);
        }

        // GET: Order/Create
        public ActionResult Create()
        {
            var order = new Order
            {
                Time = DateTime.Now,
                Date = DateTime.Now,

            };
            ViewBag.HospitalID = new SelectList(db.Hospitals, "HospitalID", "Name");
            ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "First_Name");
            return View(order);
        }

        // POST: Order/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "OrderID,HospitalID,StaffID,Date,Time")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();

                return RedirectToAction("Details", new { id = order.OrderID });
            }


            ViewBag.HospitalID = new SelectList(db.Hospitals, "HospitalID", "Name", order.HospitalID);
            ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "First_Name", order.StaffID);
            return View(order);
        }

        // GET: Order/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Order order = db.Orders.Find(id);
            if (order == null)
            {
                return HttpNotFound();
            }
            ViewBag.DeliveryID = new SelectList(db.Deliverys, "DeliveryID", "DeliveryID", order.DeliveryID);
            ViewBag.HospitalID = new SelectList(db.Hospitals, "HospitalID", "Name", order.HospitalID);
            ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "First_Name", order.StaffID);
            return View(order);
        }

        // POST: Order/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "OrderID,HospitalID,StaffID,DeliveryID,Date,Time")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Details", new { id = order.OrderID });
            }
            ViewBag.DeliveryID = new SelectList(db.Deliverys, "DeliveryID", "DeliveryID", order.DeliveryID);
            ViewBag.HospitalID = new SelectList(db.Hospitals, "HospitalID", "Name", order.HospitalID);
            ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "First_Name", order.StaffID);
            return View(order);
        }

        // GET: Order/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Order order = db.Orders.Find(id);
            if (order == null)
            {
                return HttpNotFound();
            }
            return View(order);
        }

        // POST: Order/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Order order = db.Orders.Find(id);
            db.Orders.Remove(order);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

Order Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace HealthHabitat.Models
{
    public class Order
    {
        public int OrderID { get; set; }

        [Display(Name = "Hospital")]
        public int HospitalID { get; set; }

        [Display(Name = "Staff")]
        public int StaffID { get; set; }
        public int? DeliveryID { get; set; }

        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Date { get; set; }

        [DataType(DataType.Time)]
        [DisplayFormat(DataFormatString = "{0:HH:mm}", ApplyFormatInEditMode = true)]
        public DateTime Time { get; set; }

        public virtual Hospital Hospital { get; set; }
        public virtual Staff Staff { get; set; }
        public virtual Delivery Delivery { get; set; }
        public virtual ICollection<OrderItem> OrderItems { get; set; }
    }
}
mustang00
  • 293
  • 1
  • 8
  • 21
  • Kinda "depends" on your operational flow. Typically, this maps to a "fulfillment" flow where "orders ready for fulfillment" are *batched* based on some _status_. This makes fulfillment "automated" - batched to a "fulfillment center"/operation. Which may have it's own automation processes - e.g. which carrier? type of delivery service level? etc....Hth.. – EdSF Aug 29 '15 at 15:06
  • @EdSF Currently, I don't have a `batch` because the relationship between `Order` and `Delivery` is - a `Delivery` can have many `Orders` and a `Order` is part of one and only one `Delivery`. It's for a fairly small company, and the business processes aren't very complex. So I wasn't sure if I really needed one. – mustang00 Aug 29 '15 at 15:13
  • I think what you're saying is that you have "many fulfillment centers" (carriers/drivers), and that the manual (currently) process is figuring out which "carrier/driver" handles which order? If so, is there anything in that decision process that can be automated (e.g. delivery zone/area)? – EdSF Aug 29 '15 at 15:33
  • Convert your Edit view to a Partial View – Gregg Aug 29 '15 at 19:47
  • There are dozens of ways you could do this. One is to use the `BeginCollectionItem` helper of javascript/jquery to dynamically add new Order items items in the Delivery form (some examples [here](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796) and [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308). Another would be to use a checklist box in the Delivery form so that you can select existing orders to include. –  Aug 30 '15 at 00:16
  • @StephenMuecke for the checkbox, how would I go about doing that? That would seem like the simpler method. – mustang00 Aug 30 '15 at 07:59
  • So are all your orders created first? If so what properties of Order do you need to post back (just its `ID` - and some other property for display?) –  Aug 30 '15 at 08:03
  • Yes, all my Orders are created first and I just need to display the ID and some other properties, like the hospital it goes to and the date and time for e.g. I chose the properties that I want to display in my `Delivery Details View`. – mustang00 Aug 30 '15 at 08:07
  • The DeliveryDetails view appears to be a 'readonly' view (not for editing). It would make more sense to add checkboxes for each order in the 'Create' and/or 'Edit' view for a delivery. –  Aug 30 '15 at 08:16
  • Sure, that would make more sense. I would prefer to have it in the edit, I just thought that I could add it in the delivery details page after having created my delivery. – mustang00 Aug 30 '15 at 09:57

1 Answers1

3

You could add a checked list box for all Orders to the views that create and edit a Delivery.

Start with view models representing what you want to display and edit

public class OrderVM
{
  public int ID { get; set; }
  public string Name { get; set; }
  public bool IsSelected { get; set; }
}
public class DeliveryVM
{
  public int? ID { get; set; }
  public int DriverID { get; set; }
  public SelectList DriverList { get; set; }
  public List<OrderVM> Orders { get; set; }
}

Controller

public ActionResult Create()
{
  DeliveryVM model = new DeliveryVM()
  {
    DriverList = new SelectList(db.Drivers, "DriverID", "First_Name"),
    Orders = db.Orders.Where(...).Select(o => new OrderVM()
    {
      ID = o.OrderID,
      Name = // build the display string you want based on other properties
    }).ToList()
  };
  return View(model);
}
public ActionResult Create(DeliveryVM model)
{
  Delivery delivery = new Delivery()
  {
    DriverID = model.DriverID,
    // map other properties of the view model to the data model
    Dispatched_Date = DateTime.Now, // set here, NOT in the GET method
    ....
  }
  db.Deliverys.Add(delivery);
  db.SaveChanges();
  // save the selected orders based on the ID of the Delivery object
  IEnumerable<int> selectedOrders = model.Orders.Where(o => o.IsSelected).Select(o => o.ID);
  foreach (int ID in selectedOrders)
  {
    Order order = db.Orders.Where(o => o.OrderID == ID).FirstOrDefault();
    order.DeliveryID = delivery.DeliveryID;
    db.Orders(order).State = EntityState.Modified
  }
  db.SaveChanges();
  // redirect
}

And in the view

@model DeliveryVM
@using (Html.BeginForm())
{
  @Html.DropDownListFor(m => m.DriverID, Model.DriverList, "-Please select-")
  ....
  for(int i = 0; i < Model.Orders.Count; i++)
  {
    @Html.HiddenForFor(m => m.Orders[i].ID)
    @Html.CheckBoxFor(m => m.Orders[i].IsSelected)
    @Html.LabelFor(m => m.Orders[i].IsSelected, Model.Orders[i].Name)
    // include hidden input for the name if you likely to return the view
  }
  <input type="submit" ../>
}

The Edit methods would be similar except you map the values of existing objects to the view model, and in the POST method, you call the database to get the existing objects and update their properties from the view model.

Side note: Your data models appear to include numerous DateTime and properties which should not be editable therefore should not be included in the view model. Properties such as Dispatched_Date should never be set in the GET method, only immediately before you save. In addition your opening yourself up to overposting attacks by your use of the [Bind] attribute - your including all properties so a malicious user could easily post invalid dates causing your app to fail. Using a view model means you never need to use the attribute

  • Hi again, with regards to this `Orders = db.Orders.Where(...).Select(o => new OrderVM()` - I'm just a bit confused as to what goes in the where clause. For example, the details I want are `OrderID` and `Hospital Name` and `Date`. So would I say `db.Orders.Where(o => Order.OrderID && Hospital.HospitalName && Order.Date)`? – mustang00 Aug 30 '15 at 15:56
  • Also, if I wanted to only add `Orders` within a certain range, lets say within a date range maybe. How would I apply that? In the event that there are a ton of Orders to select. – mustang00 Aug 30 '15 at 18:16
  • No, the `.Where()` is used for filtering the collection, for example `.Where(o => o.Date > someDate && o.Date < anotherDate )` if you wanted to get only orders between 2 dates –  Aug 30 '15 at 21:47
  • Hi, there seems to be something missing from this code even after I added the properties I need. `Orders = db.Orders.Where(...).Select(o => new OrderVM() { ID = o.OrderID, Name = // build the display string you want based on other properties }` - Not sure if its a bracket or semi-colon. Any ideas? – mustang00 Aug 31 '15 at 09:48
  • 1
    I've added the bracket but it seems to have a problem with this line `db.Orders.Where(o => o.Expected_Date == DateTime.Now).Select` its saying that it cannot implicitly convert type 'System.Linq.IQueryable to 'System.Collections.Generic.List' . An explicit conversion exists (are you missing a cast?). – mustang00 Aug 31 '15 at 10:03
  • You can add `ToList()` - see update. Note also `o.Expected_Date == DateTime.Now` may not return anything since `DateTime.Now` returns a very exact date (seconds) - you may want to use `DateTime.Date`? –  Aug 31 '15 at 10:22
  • Thank you, that worked. However, now the line `model.Orders.Where(o => o.IsSelected);` seems to be bombing out as well. I tried adding the `.ToList()` there but that didn't work. Sorry to be such a bother. – mustang00 Aug 31 '15 at 11:04
  • Sorry, supposed to be `OrderVM` not `int` (or if its was `int` then it would be `model.Orders.Where(o => o.IsSelected).Select(o => o.ID);` - see edit –  Aug 31 '15 at 11:07
  • Hmm for some reason, it's not displaying the orders on my create page. – mustang00 Aug 31 '15 at 11:51
  • Whats not displaying on your create page? –  Aug 31 '15 at 11:52
  • Do you have any orders matching your query? Put a break point on `return View(model);` and check the value of `model` –  Aug 31 '15 at 11:55
  • Apologies, my mistake. I forgot to change the date of the orders to today's date. But, it times out when you have to save. It goes back to this line `IEnumerable selectedOrders = model.Orders.Where(o => o.IsSelected);` – mustang00 Aug 31 '15 at 11:56
  • You have not shown how you save :) And the line `IEnumerable selectedOrders = model.Orders.Where(o => o.IsSelected);` has nothing to do with it. That just gets the collection of orders you selected in the view (and will take less than a millisecond to run) –  Aug 31 '15 at 11:59
  • Lol, my bad. Well, on my create page, the code for creating is `` - So I select the orders available and after that I click that. – mustang00 Aug 31 '15 at 12:04
  • Actually. It works now, but I don't think it linked the order. Because it doesn't show up on the Orders that are linked to the Delivery. Any idea? – mustang00 Aug 31 '15 at 12:06
  • Without knowing how your saving the data, impossible to tell. You would need to loop through `selectedOrders`, get the associated `Order` model from the database based on the selected `ID` property of `OrderVM` and set its DeliveryID = delivery.DeliveryID`. If its not saving to the database, then you will need to ask as new question with the actual code you have used –  Aug 31 '15 at 12:15
  • Could you please elaborate? – mustang00 Aug 31 '15 at 12:56
  • I have edited the question with some sample code, but you have posted far too much code for me to wade through to be sure it 100% correct. If you still having problems, then you need to post a new question focusing on just the specific issue and with only the relevant code. –  Aug 31 '15 at 13:15
  • Hi Stephen, sorry to bother you once again, but this line `db.Orders(order).State = EntityState.Modified` - it seems that the `db.Orders` is underlined with an error saying, Non-ivocable member cannot be used as a method. I'm not sure what to do about that. – mustang00 Aug 31 '15 at 16:48
  • It might need to be `db.Entry(order).State = EntityState.Modified;` but if that does not solve the issue, please ask a NEW question with just the relevant code and details of the error –  Sep 01 '15 at 01:12