// GET: /Customer/
        public ActionResult Index()
        {
			Log.Debug("GET/Index");
			using(var uow = new UoW()){
				var customersRepo = uow.GetRepository<ICustomerRepository>();
				var customers = customersRepo.GetQuery().Include(c => c.Creator).ToList();
                return View("Index", (object)JsonConvert.SerializeObject(customers));
			}
        }
        public ActionResult Create([Bind(Include="Id,FirstName,LastName,Company,Email,City,Postal,Street,Country,CreatorId,ModificationDate,CreationDate")] Customer customer)
        {
			Log.Debug("POST/Create");
            if (ModelState.IsValid)
            {
				using(var uow = new UoW()){
					var customersRepo = uow.GetRepository<ICustomerRepository>();
					customersRepo.Add(customer);
					uow.SaveChanges();
				}
                return RedirectToAction("Index");
            }

			using(var uow = new UoW()){
                //ViewBag.CreatorId = new SelectList(uow.IdentityUsers.GetAll(), "Id", "UserName");
			}
            return View(customer);
        }
        // GET: /Customer/Details/5
        public ActionResult Details(int? id)
        {
			Log.Debug("GET/Details id: {0}", id.ToString());
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Customer customer = null;
			using(var uow = new UoW()){
				var customersRepo = uow.GetRepository<ICustomerRepository>();
				customer = customersRepo.GetByKey((System.Int32)id);
			}
            if (customer == null)
            {
                return HttpNotFound();
            }
            return View(customer);
        }
        // GET: /Customer/Edit/5
        public ActionResult Edit(int? id)
        {
			Log.Debug("GET/Edit id:{0}", id.ToString());
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Customer customer = null;
			using(var uow = new UoW()){
				var customersRepo = uow.GetRepository<ICustomerRepository>();
				customer = customersRepo.GetByKey((System.Int32)id);
			}
            if (customer == null)
            {
                return HttpNotFound();
            }
			using(var uow = new UoW()){
                //ViewBag.CreatorId = new SelectList(uow.IdentityUsers.GetAll(), "Id", "UserName");
			}
            return View(customer);
        }
        public ActionResult DeleteConfirmed(int id)
        {
			Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString());
			using(var uow = new UoW()){
				var customersRepo = uow.GetRepository<ICustomerRepository>();
				var customer = customersRepo.GetByKey((System.Int32)id);
				customersRepo.Delete(customer);
				uow.SaveChanges();
			}
            return RedirectToAction("Index");
        }
        public ActionResult Edit([Bind(Include="Id,FirstName,LastName,Company,Email,City,Postal,Street,Country,CreatorId,ModificationDate,CreationDate")] Customer customer)
        {
			Log.Debug("POST/Edit");
            if (ModelState.IsValid)
            {
				using(var uow = new UoW()){
					var customersRepo = uow.GetRepository<ICustomerRepository>();
                    var customermodify = customersRepo.GetByKey(customer.Id);
                    customermodify.FirstName = customer.LastName;
                    customermodify.LastName = customer.LastName;
                    customermodify.Company = customer.Company;
                    customermodify.Email = customer.Email;
                    customermodify.Street = customer.Street;
                    customermodify.Postal = customer.Postal;
                    customermodify.Country = customer.Country;
                    customermodify.City = customer.City;
                    customersRepo.Update(customermodify);
                    uow.SaveChanges();
                    return RedirectToAction("Details", new { @id = customer.Id });
				}
			}	
			using(var uow = new UoW()){
                //ViewBag.CreatorId = new SelectList(uow.IdentityUsers.GetAll(), "Id", "UserName");
			}
            return View(customer);
        }