Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        // DELETE: api/Customer/5
        public bool DeleteCustomer(int id)
        {
            restProperties.Method     = "Delete";
            restProperties.MethodType = Method.GET;
            restProperties.Parameters = new List <CIRestParameter>();
            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "id",
                value = id
            });

            IRestResponse <int> response = CIRestService.ExecuteRestRequest <int>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                if (response.Data > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
        }
Beispiel #3
0
        // GET: Customer
        public ActionResult Index()
        {
            List <CustomerViewModel> customerVMList = new List <CustomerViewModel>();

            restProperties.Method     = "GetCustomerList";
            restProperties.MethodType = Method.GET;

            IRestResponse <List <Customer> > response = CIRestService.ExecuteRestRequest <List <Customer> >(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                foreach (Customer customer in response.Data)
                {
                    CustomerViewModel customerVM = new CustomerViewModel();
                    customerVM.CustomerId = customer.Id;
                    customerVM.FirstName  = customer.FirstName;
                    customerVM.LastName   = customer.LastName;
                    customerVMList.Add(customerVM);
                }
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }

            return(View(customerVMList));
        }
Beispiel #4
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                restProperties.Method     = "DeleteCustomer";
                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.Data)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
                }
                // TODO: Add delete logic here
            }
            catch
            {
                return(View());
            }
        }
        private void GetContactTypesandStatus(out List <ContactType> contactTypes, out Dictionary <string, string> ContactStatusList)
        {
            restProperties.Method     = "GetContactTypes";
            restProperties.MethodType = Method.GET;
            restProperties.Controller = typeof(ContactType).Name;
            IRestResponse <ContactType> contactTypeResponse = CIRestService.ExecuteRestRequest <ContactType>(restProperties, client);

            contactTypes      = JsonConvert.DeserializeObject <List <ContactType> >(contactTypeResponse.Content);
            ContactStatusList = new Dictionary <string, string>()
            {
                { Status.Active.ToString(), Status.Active.ToString() },
                { Status.Inactive.ToString(), Status.Inactive.ToString() },
            };
        }
Beispiel #6
0
        public List <Customer> GetCustomerList()
        {
            restProperties.Method     = "GetCustomerList";
            restProperties.MethodType = Method.GET;

            IRestResponse <List <Customer> > response = CIRestService.ExecuteRestRequest <List <Customer> >(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(response.Data);
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
        }
Beispiel #7
0
        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());
            }
        }
Beispiel #8
0
        // GET: Customer/Details/5
        public ActionResult Details(int id)
        {
            CustomerViewModel customerVM = new CustomerViewModel();

            restProperties.Method     = "GetCustomerwithContacts";
            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)
            {
                Customer customer = Newtonsoft.Json.JsonConvert.DeserializeObject <Customer>(response.Content);
                if (customer != null)
                {
                    customerVM.CustomerId       = customer.Id;
                    customerVM.FirstName        = customer.FirstName;
                    customerVM.LastName         = customer.LastName;
                    customerVM.CustomerContacts = new List <CustomerContactViewModel>();
                    foreach (CustomerContact contact in customer.CustomerContacts)
                    {
                        CustomerContactViewModel contactVM = new CustomerContactViewModel();
                        contactVM.CutsomerContactId = contact.Id;
                        contactVM.CustomerId        = contact.CustomerId;
                        contactVM.ContactTypeId     = contact.ContactTypeId;
                        contactVM.ContactTypeText   = contact.ContactType?.Type;
                        contactVM.ContactValue      = contact.ContactValue;
                        contactVM.ContactStatus     = contact.ContactStatus;
                        customerVM.CustomerContacts.Add(contactVM);
                    }
                }
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }

            return(View(customerVM));
        }
        private CustomerContactViewModel GetCustomerContctInfo(int id)
        {
            CustomerContactViewModel    customerContactVm = new CustomerContactViewModel();
            List <ContactType>          contactTypes;
            Dictionary <string, string> ContactStatusList;

            GetContactTypesandStatus(out contactTypes, out ContactStatusList);

            customerContactVm         = new CustomerContactViewModel();
            restProperties.Controller = typeof(CustomerContact).Name;
            restProperties.Method     = "GetContactInformation";
            restProperties.MethodType = Method.GET;

            restProperties.Parameters = new List <CIRestParameter>();
            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "id",
                value = id
            });

            IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                CustomerContact customerContact = Newtonsoft.Json.JsonConvert.DeserializeObject <CustomerContact>(response.Content);
                if (customerContact != null)
                {
                    customerContactVm.CutsomerContactId = customerContact.Id;
                    customerContactVm.CustomerId        = customerContact.CustomerId;
                    customerContactVm.CustomerName      = customerContact.Customer?.FirstName + " " + customerContact.Customer?.LastName;
                    customerContactVm.ContactTypeList   = new SelectList(contactTypes, "Id", "Type", customerContact.ContactTypeId);
                    customerContactVm.ContactTypeId     = customerContact.ContactTypeId;
                    customerContactVm.ContactTypeText   = customerContact.ContactType?.Type;
                    customerContactVm.ContactValue      = customerContact.ContactValue;
                    customerContactVm.ContactStatus     = customerContact.ContactStatus;
                    customerContactVm.ContactStatusList = new SelectList(ContactStatusList, "Key", "Value", customerContact.ContactStatus);
                }
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
            return(customerContactVm);
        }
        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 CustomerContact SaveContact(CustomerContact contact)
        {
            restProperties.Method     = "Save";
            restProperties.MethodType = Method.POST;

            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "customerContact",
                value = contact
            });

            IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(response.Data);
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
        }
        public CustomerContact GetContactInformation(int id)
        {
            restProperties.Method     = "GetContactInformation";
            restProperties.MethodType = Method.GET;

            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "id",
                value = id
            });

            IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <CustomerContact>(response.Content));
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
        }
        public CustomerContact GetCustomerContact(int id)
        {
            restProperties.Method     = "Edit";
            restProperties.MethodType = Method.GET;

            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "id",
                value = id
            });

            IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(response.Data);
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
        }
        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());
            }
        }
Beispiel #15
0
        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);
            }
        }