Click here to Skip to main content
12,360,037 members (62,365 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads

Stats

294.6K views
21K downloads
412 bookmarked
Posted

MVC Techniques with jQuery, JSON, Knockout, and C#

, 2 Jan 2012 CPOL
Developing an Order Entry application with MVC.
ADODataService
ADODataService.csproj.user
bin
Debug
ADODataService.dll
Release
obj
Debug
TempPE
Release
Properties
NorthwindApplicationServices
bin
Debug
ADODataService.dll
NorthwindApplicationServices.dll
NorthwindBusinessServices.dll
NorthwindDataAccessServices.dll
NorthwindDataModel.dll
NorthwindViewModel.dll
Release
NorthwindApplicationServices.csproj.user
obj
Debug
TempPE
Release
Properties
NorthwindBusinessServices
bin
Debug
ADODataService.dll
NorthwindBusinessServices.dll
NorthwindDataAccessServices.dll
NorthwindDataModel.dll
NorthwindViewModel.dll
Release
NorthwindBusinessServices.csproj.user
obj
Debug
TempPE
Release
Properties
NorthwindDataAccessServices
bin
Debug
ADODataService.dll
NorthwindDataAccessServices.dll
NorthwindDataModel.dll
Release
NorthwindDataAccessServices.csproj.user
obj
Debug
TempPE
Release
Properties
NorthwindDataModel
bin
Debug
NorthwindDataModel.dll
Release
NorthwindDataModel.csproj.user
obj
Debug
TempPE
Release
Properties
NorthwindViewModel
bin
Debug
NorthwindDataModel.dll
NorthwindViewModel.dll
Release
NorthwindViewModel.csproj.user
obj
Debug
TempPE
Release
Properties
NorthwindWebApplication
App_Data
bin
ADODataService.dll
EntityFramework.dll
Microsoft.Web.Infrastructure.dll
Microsoft.Web.Optimization.dll
NorthwindApplicationServices.dll
NorthwindBusinessServices.dll
NorthwindDataAccessServices.dll
NorthwindDataModel.dll
NorthwindViewModel.dll
NorthwindWebApplication.dll
NorthwindWebControls.dll
System.Web.Helpers.dll
System.Web.Mvc.dll
System.Web.Providers.dll
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
Content
Images
DownArrow.gif
icon-calendar.gif
icon-delete.gif
icon-floppy.gif
icon-pencil-x.gif
icon-pencil.gif
Search3.gif
UpArrow.gif
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
Global.asax
Helpers
Images
accent.png
aspNetHome.png
bullet.png
facebook.png
findHosting.png
heroAccent.png
NuGetGallery.png
orderedListOne.png
orderedListThree.png
orderedListTwo.png
Search.gif
twitter.png
windowsLive.png
Models
NorthwindWebApplication.csproj.user
obj
Debug
TempPE
Properties
Scripts
Views
Account
Home
Orders
Products
Shared
NorthwindWebControls
bin
Debug
NorthwindWebControls.dll
Release
obj
Debug
TempPE
Properties
packages
AspNetMvc.4.0.10906.0
AspNetMvc.4.0.10906.0.nupkg
lib
net40
System.Web.Mvc.dll
AspNetWebPagesCore.2.0.10906.0
AspNetWebPagesCore.2.0.10906.0.nupkg
lib
net40
System.Web.Helpers.dll
System.Web.Razor.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
EntityFramework.4.1.10331.0
EntityFramework.4.1.10331.0.nupkg
lib
net40
EntityFramework.dll
jQuery.1.6.2
Content
Scripts
jQuery.1.6.2.nupkg
jQuery.Ajax.Unobtrusive.1.0
Content
Scripts
jQuery.Ajax.Unobtrusive.1.0.nupkg
jQuery.UI.Combined.1.8.11
Content
Content
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Scripts
jQuery.UI.Combined.1.8.11.nupkg
jQuery.Validation.1.8
Content
Scripts
jQuery.Validation.1.8.nupkg
jQuery.Validation.Unobtrusive.1.0
Content
Scripts
jQuery.Validation.Unobtrusive.1.0.nupkg
knockoutjs.1.2.9.0
Content
Scripts
knockoutjs.1.2.9.0.nupkg
Microsoft.Web.Optimization.0.1
lib
net40
Microsoft.Web.Optimization.dll
Microsoft.Web.Optimization.0.1.nupkg
MicrosoftWebInfrastructure.1.0.0.0
lib
net40
Microsoft.Web.Infrastructure.dll
MicrosoftWebInfrastructure.1.0.0.0.nupkg
Modernizr.2.0.6
Content
Scripts
Modernizr.2.0.6.nupkg
System.Web.Providers.1.0.1
content
web.config.transform
EULA.rtf
lib
Net40
System.Web.Providers.dll
System.Web.Providers.1.0.1.nupkg
SQLScript
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NorthwindViewModel;
using NorthwindDataModel;
using NorthwindDataAccessServices;
using NorthwindBusinessServices;

namespace NorthwindApplicationServices
{
    public class OrderApplicationService
    {

        /// <summary>
        /// Start Order Entry
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public OrderViewModel BeginOrderEntry(string customerID)
        {
          
            CustomerDataAccessService customerDataAccessService = new CustomerDataAccessService();         
            Customer customer = customerDataAccessService.GetCustomerInformation(customerID);
       
            OrderViewModel orderViewModel = new OrderViewModel();
            orderViewModel.Customer = customer;

            OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
            orderViewModel.Shippers = orderDataAccessService.GetShippers();

            OrderBusinessService orderBusinessService = new OrderBusinessService();
            orderViewModel.Order = orderBusinessService.InitializeOrderHeader(customer);

            return orderViewModel;

        }


        /// <summary>
        /// Start Order Edit
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public OrderViewModel BeginOrderEdit(int orderID)
        {

            OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
            OrderViewModel orderViewModel = new OrderViewModel();

            OrdersCustomer orderCustomer = orderDataAccessService.GetOrder(orderID);
            orderCustomer.Order.OrderTotal = orderDataAccessService.GetOrderTotal(orderID);
            orderCustomer.Order.OrderTotalFormatted = orderCustomer.Order.OrderTotal.ToString("C");

            orderViewModel.Customer = orderCustomer.Customer;
            orderViewModel.Order = orderCustomer.Order;           
            orderViewModel.Shippers = orderDataAccessService.GetShippers();
            orderViewModel.Order.ShipperName = orderCustomer.Shipper.CompanyName;

            return orderViewModel;

        }

        /// <summary>
        /// Get Order Details
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public OrderViewModel GetOrderDetails(int orderID)
        {

            OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
            OrderViewModel orderViewModel = new OrderViewModel();

            List<OrderDetailsProducts> orderDetailsProducts = orderDataAccessService.GetOrderDetails(orderID);
            OrdersCustomer orderCustomer = orderDataAccessService.GetOrder(orderID);
            orderViewModel.OrderDetailsProducts = orderDetailsProducts;
            orderViewModel.Order = orderCustomer.Order;
            orderViewModel.Customer = orderCustomer.Customer;
          
            return orderViewModel;

        }

        /// <summary>
        /// Add Order Detail Line Item
        /// </summary>
        /// <param name="orderViewModel"></param>
        /// <returns></returns>
        public OrderViewModel AddOrderDetailLineItem(OrderViewModel orderViewModel)
        {
            try
            {
                OrderBusinessService orderBusinessService = new OrderBusinessService();
                orderBusinessService.ValidateOrderDetail(orderViewModel.OrderDetail, true);
                if (orderBusinessService.ValidationStatus == false)
                {
                    orderViewModel.ReturnMessage = orderBusinessService.ValidationMessage;
                    orderViewModel.ReturnStatus = false;
                    orderViewModel.ValidationErrors = orderBusinessService.ValidationErrors;
                    return orderViewModel;
                }

                OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
                orderDataAccessService.CreateOrderDetailLineItem(orderViewModel.OrderDetail);

                OrderDetailsProducts orderDetailsProducts = orderDataAccessService.GetOrderDetails(
                    orderViewModel.OrderDetail.OrderID, orderViewModel.OrderDetail.ProductID);

                orderViewModel.OrderLineItem = orderDetailsProducts;
                orderViewModel.ReturnStatus = true;

                List<String> returnMessage = new List<String>();
                returnMessage.Add("Order line item has been added at " + DateTime.Now.ToString());
                orderViewModel.ReturnMessage = returnMessage;
             
            }
            catch (Exception ex)
            {
                List<String> returnMessage = new List<String>();
                returnMessage.Add(ex.Message);

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = false;
            }

            return orderViewModel;

        }

        /// <summary>
        /// Update Order Detail Line Item
        /// </summary>
        /// <param name="orderViewModel"></param>
        /// <returns></returns>
        public OrderViewModel UpdateOrderDetailLineItem(OrderViewModel orderViewModel)
        {
            try
            {
                OrderBusinessService orderBusinessService = new OrderBusinessService();
                orderBusinessService.ValidateOrderDetail(orderViewModel.OrderDetail, false);
                if (orderBusinessService.ValidationStatus == false)
                {
                    orderViewModel.ReturnMessage = orderBusinessService.ValidationMessage;
                    orderViewModel.ReturnStatus = false;
                    orderViewModel.ValidationErrors = orderBusinessService.ValidationErrors;
                    return orderViewModel;
                }

                OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
                orderDataAccessService.UpdateOrderDetailLineItem(orderViewModel.OrderDetail);

                OrderDetailsProducts orderDetailsProducts = orderDataAccessService.GetOrderDetails(
                    orderViewModel.OrderDetail.OrderID, orderViewModel.OrderDetail.ProductID);

                orderViewModel.OrderLineItem = orderDetailsProducts;
                orderViewModel.ReturnStatus = true;

                List<String> returnMessage = new List<String>();
                returnMessage.Add("Order line item has been updated at " + DateTime.Now.ToString());
                orderViewModel.ReturnMessage = returnMessage;

            }
            catch (Exception ex)
            {
                List<String> returnMessage = new List<String>();
                returnMessage.Add(ex.Message);

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = false;
            }

            return orderViewModel;

        }

     
         /// <summary>
        /// Delete Order Detail Line Item
        /// </summary>
        /// <param name="orderViewModel"></param>
        /// <returns></returns>
        public OrderViewModel DeleteOrderDetailLineItem(OrderViewModel orderViewModel)
        {
            try
            {
                OrderBusinessService orderBusinessService = new OrderBusinessService();

                int productID = orderViewModel.OrderLineItem.OrderDetails.ProductID;
                int orderID = orderViewModel.OrderLineItem.OrderDetails.OrderID;

                OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
                orderDataAccessService.DeleteOrderDetailLineItem(orderID, productID);
              
                orderViewModel.ReturnStatus = true;

                List<String> returnMessage = new List<String>();
                returnMessage.Add(orderViewModel.OrderLineItem.Products.ProductName + " has been delete from this order at " + DateTime.Now.ToString());
                orderViewModel.ReturnMessage = returnMessage;

            }
            catch (Exception ex)
            {
                List<String> returnMessage = new List<String>();
                returnMessage.Add(ex.Message);

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = false;
            }

            return orderViewModel;

        }

        /// <summary>
        /// Create Order
        /// </summary>
        /// <param name="orderViewModel"></param>
        /// <returns></returns>
        public OrderViewModel CreateOrder(OrderViewModel orderViewModel)
        {
            try
            {

                OrderBusinessService orderBusinessService = new OrderBusinessService();
                orderBusinessService.ValidateOrderHeader(orderViewModel.Order);
                if (orderBusinessService.ValidationStatus == false)
                {
                    orderViewModel.ReturnMessage = orderBusinessService.ValidationMessage;
                    orderViewModel.ReturnStatus = false;
                    orderViewModel.ValidationErrors = orderBusinessService.ValidationErrors;
                    return orderViewModel;
                }

                OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
                orderDataAccessService.CreateOrder(orderViewModel.Order);
                orderViewModel = BeginOrderEdit(orderViewModel.Order.OrderID);
                orderViewModel.Order.RequiredDateFormatted = orderViewModel.Order.RequiredDate.ToShortDateString();

                List<String> returnMessage = new List<String>();
                returnMessage.Add("Order number " + orderViewModel.Order.OrderID.ToString() + " has been created.");

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = true;

            }
            catch (Exception ex)
            {
                List<String> returnMessage = new List<String>();
                returnMessage.Add(ex.Message);

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = false;
            }
         
            return orderViewModel;

        }


        /// <summary>
        /// Update Order
        /// </summary>
        /// <param name="orderViewModel"></param>
        /// <returns></returns>
        public OrderViewModel UpdateOrder(OrderViewModel orderViewModel)
        {
            try
            {

                OrderBusinessService orderBusinessService = new OrderBusinessService();
                orderBusinessService.ValidateOrderHeader(orderViewModel.Order);
                if (orderBusinessService.ValidationStatus == false)
                {
                    orderViewModel.ReturnMessage = orderBusinessService.ValidationMessage;
                    orderViewModel.ReturnStatus = false;
                    orderViewModel.ValidationErrors = orderBusinessService.ValidationErrors;
                    return orderViewModel;
                }

                OrderDataAccessService orderDataAccessService = new OrderDataAccessService();
                orderDataAccessService.UpdateOrder(orderViewModel.Order);
                orderViewModel = BeginOrderEdit(orderViewModel.Order.OrderID);
                orderViewModel.Order.RequiredDateFormatted = orderViewModel.Order.RequiredDate.ToShortDateString();

                List<String> returnMessage = new List<String>();
                returnMessage.Add("Order has been updated at " + DateTime.Now.ToString());

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = true;

            }
            catch (Exception ex)
            {
                List<String> returnMessage = new List<String>();
                returnMessage.Add(ex.Message);

                orderViewModel.ReturnMessage = returnMessage;
                orderViewModel.ReturnStatus = false;
            }

            return orderViewModel;

        }

        /// <summary>
        /// Customer Inquiry
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public OrderViewModel OrderInquiry(OrderViewModel viewModel)
        {

            int totalOrders;

            List<String> returnMessage = new List<String>();

            OrderDataAccessService orderDataAccessService = new OrderDataAccessService();

            try
            {
                List<OrdersCustomer> ordersCustomers = orderDataAccessService.OrderInquiry(viewModel.Order,
                    viewModel.Customer,
                    viewModel.CurrentPageNumber, 
                    viewModel.SortExpression, 
                    viewModel.SortDirection,
                    viewModel.PageSize, 
                    out totalOrders);

                viewModel.TotalOrders = totalOrders;
                viewModel.TotalPages = Utilities.CalculateTotalPages(totalOrders, viewModel.PageSize);
                viewModel.OrderCustomer = ordersCustomers;

                if (viewModel.TotalOrders > 0 && viewModel.TotalPages < viewModel.CurrentPageNumber)
                {
                    returnMessage.Add("Please resubmit your request.");
                    viewModel.ReturnMessage = returnMessage;
                    viewModel.ReturnStatus = false;
                }
                else
                {
                    returnMessage.Add(totalOrders.ToString() + " orders found.");
                    viewModel.ReturnMessage = returnMessage;
                    viewModel.ReturnStatus = true;
                }

            }
            catch
            {
                returnMessage.Add("An application error has occurred. Please call technical support.");
                viewModel.ReturnStatus = false;
            }

            viewModel.ReturnMessage = returnMessage;

            return viewModel;

        }


    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mark J. Caplin
Software Developer Caplin Systems
United States United States
Mark Caplin has specialized in Information Technology solutions for 25 years. Specializing in full life-cycle development projects for both enterprise-wide systems and Internet/Intranet based solutions.

For the past ten years or so, Mark has specialized in the Microsoft .NET framework using both C# and VB.NET as his tools of choice.

Mark currently is the Chief Solutions Architect at Joey Software Solutions, Inc. Visit Joey Software at www.joeysoftwaresolutions.com.

When not coding, Mark enjoys playing tennis, listening to U2 music, watching Miami Dolphins football and watching movies in Blu-Ray technology.

In between all this, his wife of over 20 years, feeds him well with some great home cooked meals.

...

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 Jan 2012
Article Copyright 2011 by Mark J. Caplin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid