public Customer EditCustomer(int id) { CIRestProperties restProperties = new CIRestProperties(); restProperties.Controller = typeof(Customer).Name; restProperties.Method = "Edit"; restProperties.MethodType = Method.GET; restProperties.Parameters = new List <CIRestParameter>(); restProperties.Parameters.Add(new CIRestParameter() { key = "id", value = id }); IRestResponse <Customer> response = CIRestService.ExecuteRestRequest <Customer>(restProperties, client); if (response.StatusCode == HttpStatusCode.OK) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <Customer>(response.Content)); } else { throw new Exception("Error Message " + response.ErrorMessage + "\n Exception:" + response.ErrorException); } }
public CustomerContactController() { client = new RestClient(ConfigurationManager.AppSettings["DataServiceUrl"].ToString()); restProperties = new CIRestProperties(); restProperties.Controller = typeof(CustomerContact).Name; restProperties.Parameters = new List <CIRestParameter>(); }
public ActionResult Create(CustomerViewModel customerVM) { try { Customer customer = new Customer(); customer.Id = customerVM.CustomerId; customer.FirstName = customerVM.FirstName; customer.LastName = customerVM.LastName; CIRestProperties restProperties = new CIRestProperties(); restProperties.Controller = typeof(Customer).Name; restProperties.Method = "SaveCustomer"; restProperties.MethodType = Method.POST; restProperties.Parameters = new List <CIRestParameter>(); restProperties.Parameters.Add(new CIRestParameter() { key = "customer", value = customer }); IRestResponse <Customer> response = CIRestService.ExecuteRestRequest <Customer>(restProperties, client); if (response.StatusCode == HttpStatusCode.OK) { customer = Newtonsoft.Json.JsonConvert.DeserializeObject <Customer>(response.Content); if (customer.Id > 0) { return(RedirectToAction("Index")); } else { throw new Exception("Error Message " + response.ErrorMessage + "\n Exception:" + response.ErrorException); } } else { throw new Exception("Error Message " + response.ErrorMessage + "\n Exception:" + response.ErrorException); } } catch { return(View()); } }
public ActionResult Edit(int id, CustomerContactViewModel contactVM) { try { CustomerContact contact = new CustomerContact(); contact.Id = contactVM.CutsomerContactId; contact.ContactTypeId = contactVM.ContactTypeId; contact.CustomerId = contactVM.CustomerId; contact.ContactValue = contactVM.ContactValue; contact.ContactStatus = contactVM.ContactStatus; // TODO: Add update logic here CIRestProperties restProperties = new CIRestProperties(); restProperties.Controller = typeof(CustomerContact).Name; restProperties.Method = "SaveContact"; restProperties.MethodType = Method.POST; //restProperties.Body = customer; restProperties.Parameters = new List <CIRestParameter>(); restProperties.Parameters.Add(new CIRestParameter() { key = "contact", value = contact }); IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client); if (response.StatusCode == HttpStatusCode.OK) { contact = JsonConvert.DeserializeObject <CustomerContact>(response.Content); } else { throw new Exception("Error Message " + response.ErrorMessage + "\n Exception:" + response.ErrorException); } return(RedirectToAction("Details", "Customer", new { id = contact.CustomerId })); } catch { return(View()); } }
public ActionResult Delete(int id, CustomerContactViewModel contactVM) { try { CIRestProperties restProperties = new CIRestProperties(); restProperties.Controller = typeof(CustomerContact).Name; restProperties.Method = "RemoveContact"; restProperties.MethodType = Method.GET; restProperties.Parameters = new List <CIRestParameter>(); restProperties.Parameters.Add(new CIRestParameter() { key = "id", value = id }); IRestResponse <bool> response = CIRestService.ExecuteRestRequest <bool>(restProperties, client); if (response.StatusCode == HttpStatusCode.OK) { if (response.Data) { return(RedirectToAction("Details", "Customer", new { id = contactVM.CustomerId })); } else { RedirectToAction("Delete", new { id = id }); } } throw new Exception("Error Message " + response.ErrorMessage + "\n Exception:" + response.ErrorException); // TODO: Add delete logic here } catch { return(View()); } }
public Customer GetCustomerwithContacts(int id) { ContactTypeController contactTypeController = new Controllers.ContactTypeController(); List <ContactType> contactTypes = contactTypeController.GetContactTypes(); CIRestProperties restProperties = new CIRestProperties(); restProperties.Controller = typeof(Customer).Name; restProperties.Method = "LoadCustomerInfo"; restProperties.MethodType = Method.GET; restProperties.Parameters = new List <CIRestParameter>(); restProperties.Parameters.Add(new CIRestParameter() { key = "customerId", value = id }); IRestResponse <Customer> response = CIRestService.ExecuteRestRequest <Customer>(restProperties, client); if (response.StatusCode == HttpStatusCode.OK) { Customer customer = Newtonsoft.Json.JsonConvert.DeserializeObject <Customer>(response.Content); foreach (CustomerContact contact in customer.CustomerContacts) { contact.ContactType = contactTypes.FirstOrDefault(x => x.Id == contact.ContactTypeId); } return(customer); } else { throw new Exception("Error Message " + response.ErrorMessage + "\n Exception:" + response.ErrorException); } }
public CustomerContactController() { client = new RestClient(ConfigurationManager.AppSettings["BusinessServiceUrl"].ToString()); restProperties = new CIRestProperties(); restProperties.Controller = typeof(CustomerContact).Name; }