public IHttpActionResult PutCustomer(CustomerVM customer)
        {
            if (!ModelState.IsValid)
            {
                
                return Content(HttpStatusCode.BadRequest, BadRequest(ModelState));
            }

            if (customerManager.GetCustomer(Convert.ToInt32(customer.Id)) == null)
            {
                
                return Content(HttpStatusCode.NotFound, NotFound());
            }

            try
            {
                if (customerManager.UpdateCustomer(customer))
                {
                    
                    return Content(HttpStatusCode.OK, true);
                }
                else {
                   
                    return Content(HttpStatusCode.BadRequest, StatusCode(HttpStatusCode.NoContent));
                }
            }
            catch
            {
                
                return Content(HttpStatusCode.BadRequest, BadRequest(ModelState));
            }
        }
 public void TestInsertCustomer()
 {
     CustomerVM cvm = new CustomerVM();
     cvm.CustName = "Harison Ford";
     cvm.CustEmail = "*****@*****.**";
     long testCustId = custMngr.InsertCustomer(cvm);
     Assert.IsTrue(testCustId >= 0);
 }
 public ActionResult Add(CustomerVM model)
 {
     if (ModelState.IsValid)
     {
         customerManager.InsertCustomer(model);
     }
     return RedirectToAction("Index");
 }
 public long InsertCustomer(CustomerVM model)
 {
     Customer cust = new Customer();
     cust.CustName = model.CustName;
     cust.CustEmail = model.CustEmail;
     CustRepository.Insert(cust);
     CustRepository.Save();
     return model.Id;
 }
        public void TestUpdateCustomer()
        {
            CustomerVM cvm = new CustomerVM();
            cvm.Id = 3;
            cvm.CustName = "Aron K";
            cvm.CustEmail = "*****@*****.**";
            Assert.IsTrue(custMngr.UpdateCustomer(cvm));

        }
        public List<CustomerVM> getAllCustomers()
        {
            List<CustomerVM> custVMs = new List<CustomerVM>();
            IEnumerable<Customer> customers = CustRepository.GetAll();
            foreach (Customer c in customers)
            {
                CustomerVM cvm = new CustomerVM();
                cvm.Id = c.Id;
                cvm.CustName = c.CustName;
                cvm.CustEmail = c.CustEmail;
                custVMs.Add(cvm);
            }

            return custVMs;
        }
        public bool UpdateCustomer(CustomerVM model)
        {
            try
            {
                Customer cust = this.CustRepository.GetById(model.Id);
               // cust.Id = model.Id;
                cust.CustName = model.CustName;
                cust.CustEmail = model.CustEmail;
                this.CustRepository.Update(cust);
                CustRepository.Save();
                return true;
            }
            catch(Exception e) {

                    return false;
                        
            }
        }
        public IHttpActionResult PostCustomer(CustomerVM customer)
        {
            if (!ModelState.IsValid)
            {
               
                return Content(HttpStatusCode.BadRequest, BadRequest(ModelState));
            }
            try
            {
                customer.Id = customerManager.InsertCustomer(customer);
            }
            catch
            {
                return Content(HttpStatusCode.BadRequest, BadRequest());
            }
            return Content(HttpStatusCode.OK, true);

           
        }
        public CustomerVM GetCustomer(int id)
        {
            CustomerVM cvm = null;
            Customer cust = new Customer();
            try
            {
                cust = this.CustRepository.GetById(id);
                cvm = new CustomerVM();
                cvm.Id = cust.Id;
                cvm.CustName = cust.CustName;
                cvm.CustEmail = cust.CustEmail;
            }
            catch
            {
                
            }

            return cvm;

        }
 public ActionResult Update(CustomerVM model)
 {
     customerManager.UpdateCustomer(model);
     return RedirectToAction("Index");
 }