- eShopping.zip
- eShopping
- AuthenticationProvider
- eShopping.Business
- bin
- Debug
- AuthenticationProvider.dll
- EntityFramework.dll
- eShopping.Business.dll
- eShopping.Common.dll
- eShopping.Entities.dll
- eShopping.eShoppingDB.dll
- CommonFunctions.cs
- eShopping.Business.csproj
- eShopping.Business.csproj.user
- IRepository
- IRepositoryServiceImpl
- obj
- Debug
- eShopping.Business.dll
- Properties
- eShopping.Common
- eShopping.DataService
- eShopping.Entities
- bin
- Debug
- EntityFramework.dll
- eShopping.Entities.dll
- Entities
- eShopping.Entities.csproj
- eShopping.Entities.csproj.user
- Properties
- eShopping.eShoppingDB
- eShopping.sln
- eShopping.UnitTests
- eShopping
- eShoppingAuthenticationProvider
- Libraries.zip
- Libraries
- AutoMapper.dll
- CKEditor.NET.dll
- EntityFramework.dll
- Moq.dll
- Newtonsoft.Json.dll
- Ninject.dll
- eShopping-noexe.zip
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using eShopping.Business.IRepository;
using eShopping.ViewModels;
using Newtonsoft.Json;
using eShopping.ActionProvider;
using eShopping.Entities.Entities;
using AutoMapper;
using System.Web.UI.WebControls;
using eShopping.Common;
namespace eShopping.Controllers
{
public class CustomerController : Controller
{
ICustomersRepository customerRepository;
public int PageSize;
public CustomerController(ICustomersRepository customerRepository)
{
this.customerRepository = customerRepository;
PageSize = 20;
}
public ActionResult List(int page)
{
try
{
var customersViewModel = new CustomersViewModel
{
Customers = customerRepository.Customers.OrderBy(x => x.CustomerID).Skip((page - 1) * PageSize).Take(PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = customerRepository.Customers.Count()
}
};
return View(customersViewModel);
}
catch (Exception ex)
{
if (ex.InnerException.Message == "Unauthorized")
{
return RedirectToAction("login", "authentication");
}
else
{
return View();
}
}
}
public ActionResult Orders(string customerId)
{
var orders = customerRepository.GetOrders(customerId);
return new JResult
{
Data = orders.ToList()
};
}
[HttpGet]
public ActionResult Add()
{
var cityList = (from customer in customerRepository.Customers
select (new { customer.City })).ToMyList<string>("City");
var CountriesList = (from customer in customerRepository.Customers
select (new { customer.Country })).ToMyList<string>("Country");
cityList.Insert(0, "--Select--");
CountriesList.Insert(0, "--Select--");
CustomerView custView = new CustomerView
{
Cities = new SelectList(cityList, cityList.FirstOrDefault()),
Countries = new SelectList(CountriesList, CountriesList.FirstOrDefault())
};
return View(custView);
}
[HttpPost]
public ActionResult Add(CustomerView customerView)
{
if (ModelState.IsValid)
{
Customer newCustomer = new Customer();
AutoMapper.Mapper.Map(customerView, newCustomer);
customerRepository.AddObject(newCustomer);
customerRepository.SaveChanges();
}
return RedirectToAction("list");
}
[HttpGet]
public ActionResult Delete(string customerId)
{
return View(customerRepository.Customers.Where(x => x.CustomerID == customerId).SingleOrDefault());
}
[HttpPost]
public ActionResult Delete(Customer customer)
{
customerRepository.DeleteObject(customerRepository.Customers.Where(x => x.CustomerID == customer.CustomerID).SingleOrDefault());
customerRepository.SaveChanges();
return RedirectToAction("list");
}
}
}
|
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.
I am vijay tanwar and i am a software engineer with passion of programming. I love to programming in c#, I love to warp up more and more things in few lines of code. my favirote languages are c# and javascript and both are fully object oriended. I always like to become the .net Architect.