Пример #1
0
        public void Delete(int id)
        {
            try
            {
                CustomerContactManagerContext cx = new CustomerContactManagerContext();
                Customer cust = cx.Customers.Find(id);
                List <CustomerContact> contactToDelete = cust.CustomerContacts.ToList();

                if (contactToDelete.Count == 0)
                {
                    cx.Customers.Remove(cust);
                }
                else
                {
                    foreach (CustomerContact cont in contactToDelete)
                    {
                        cx.CustomerContacts.Remove(cont);
                    }
                    cx.Customers.Remove(cust);
                }
                cx.SaveChanges();
            }
            catch (Exception e)
            {
                string test = "";
            }
        }
        public void Post([FromBody] CustomerContact Contact)
        {
            CustomerContactManagerContext cx = new CustomerContactManagerContext();
            var             contacts         = cx.CustomerContacts;
            CustomerContact cont             = contacts.Where(x => x.ID == Contact.ID).FirstOrDefault();


            if (cont == null)
            {
                Contact.DateCreated  = DateTime.Now;
                Contact.DateModified = DateTime.Now;

                cx.CustomerContacts.Add(Contact);
                cx.SaveChanges();
            }
            else
            {
                cont.DateModified  = DateTime.Now;
                cont.Name          = Contact.Name;
                cont.Email         = Contact.Email;
                cont.ContactNumber = Contact.ContactNumber;

                cx.SaveChanges();
            }
        }
Пример #3
0
        public void Post([FromBody] Customer customer)
        {
            try
            {
                CustomerContactManagerContext cx = new CustomerContactManagerContext();
                var      customers = cx.Customers;
                Customer cust      = customers.Where(x => x.ID == customer.ID).FirstOrDefault();

                if (cust == null)
                {
                    customer.DateCreated  = DateTime.Now;
                    customer.DateModified = DateTime.Now;

                    cx.Customers.Add(customer);
                    cx.SaveChanges();
                }
                else
                {
                    cust.DateModified = DateTime.Now;
                    cust.Name         = customer.Name;
                    cust.Longitude    = customer.Longitude;
                    cust.Latitude     = customer.Latitude;

                    cx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                string test = "";
            }
        }
        public List <CustomerContact> GetCustomerContact()
        {
            CustomerContactManagerContext cx = new CustomerContactManagerContext();

            var customerContacts            = cx.CustomerContacts;
            List <CustomerContact> contacts = customerContacts.ToList();

            return(contacts);
        }
Пример #5
0
        public Customer GetCustomer(int id)
        {
            CustomerContactManagerContext cx = new CustomerContactManagerContext();
            var      customers = cx.Customers;
            Customer cust      = customers.Where(x => x.ID == id).FirstOrDefault();

            if (cust == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(cust);
        }
Пример #6
0
        public List <Customer> GetCusomters()
        {
            CustomerContactManagerContext cx = new CustomerContactManagerContext();
            var             customers        = cx.Customers;
            List <Customer> custs            = customers.ToList();

            if (custs == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(custs);
        }
        public void Delete(int id)
        {
            CustomerContactManagerContext cx = new CustomerContactManagerContext();
            CustomerContact DelCont          = cx.CustomerContacts.Find(id);

            if (DelCont == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            cx.CustomerContacts.Remove(DelCont);
            cx.SaveChanges();
        }
        public CustomerContact GetCustomerContact(int id)
        {
            CustomerContactManagerContext cx = new CustomerContactManagerContext();


            var customerContacts = cx.CustomerContacts;
            var contact          = (from v in customerContacts
                                    where v.ID == id
                                    select v).FirstOrDefault();

            if (contact == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return(contact);
        }