public int createServiceContract(object[] serviceData)
        {
            int lastSID = new int();
            int serviceContractID = new int();
            int serviceID = (Int32)serviceData[0];
            servicetypes selectedService = null;

                //Get numbers of servicecontract in DB
                using (servicebaseEntities lc = new servicebaseEntities())
                {
                    var query = (from l in lc.servicecontracts
                                     select l.sid).Count();
                    lastSID = query;

                    var query1 = (from st in lc.servicetypes
                                 where st.tid == serviceID
                                 select st).SingleOrDefault();
                    selectedService = query1;

                //calc enddate on selected service
                DateTime startDate = (DateTime)serviceData[2];
                DateTime endDate = startDate.AddMonths(selectedService.period);
                DateTime timeStamp = DateTime.Now.Date;
                serviceContractID = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.DayOfYear.ToString() + lastSID.ToString());

                    servicecontracts sc = new servicecontracts();
                    sc.sid = serviceContractID;
                    sc.servicetype = (Int32)serviceData[0];
                    sc.soldby = (String)serviceData[1];
                    sc.startdate = startDate.Date;
                    sc.enddate = endDate.Date;
                    sc.timestamp = timeStamp;
                    lc.servicecontracts.Add(sc);
                    lc.SaveChanges();
                    lc.Dispose();
                }

                return serviceContractID;
        }
        public bool updateCustomer(int userId, object[] newData, bool serviceChanged)
        {
            //int serviceNo = 0;
            //bool hasService = false;

            /*
            if (serviceChanged)
            {
                //prepare inputdata for ServiceContract creation
                object[] serviceInput = new object[3];
                serviceInput[0] = newData[9];
                serviceInput[1] = newData[13];
                serviceInput[2] = newData[10];

                serviceNo = createServiceContract(serviceInput);

                hasService = true;

                //serviceNo++;

            }
            */

            using (servicebaseEntities sdb = new servicebaseEntities())
            {
                try
                {
                    var query = (from c in sdb.customers
                                 where c.uId == userId
                                 select c).FirstOrDefault();

                    query.cname = newData[0].ToString();
                    query.email = newData[4].ToString();
                    query.phone = newData[5].ToString();
                    query.panelcount = newData[6].ToString();
                    query.inverter = newData[8].ToString();
                    //query.serviceno = serviceNo;
                    //query.hasservice = hasService;
                    //query.servicecontracts.servicetype = Int32.Parse(newData[5].ToString()) + 1;
                    //query.servicecontracts.soldby = newData[7].ToString();

                    sdb.SaveChanges();
                }
                catch
                {

                }
                finally
                {
                    sdb.Dispose();
                }

                return true;

            }
        }
 public List<customers> searchCustomerByStreet(string searchFilter)
 {
     List<customers> tmp2 = new List<customers>();
     using (servicebaseEntities sdb = new servicebaseEntities())
     {
         try
         {   var query = from c in serviceDB.customers
                      where c.street.Contains(searchFilter)
                         select c;
              tmp2 = query.ToList();
         }
         catch
         {
         }
         finally
         {
             sdb.Dispose();
         }
         return tmp2;
     }
 }
 public List<customers> searchCustomerByServiceDate(string searchFilter)
 {
     List<customers> tmp6 = new List<customers>();
     using (servicebaseEntities sdb = new servicebaseEntities())
     {
         try
         {
             bool tmp = Boolean.Parse(searchFilter);
             var query = from c in serviceDB.customers
                         where c.hasservice == tmp
                         select c;
             tmp6 = query.ToList();
         }
         catch
         {
         }
         finally
         {
             sdb.Dispose();
         }
     return tmp6;
     }
 }
 public List<customers> searchCustomerByPostcode(string searchFilter)
 {
     List<customers> tmp4 = new List<customers>();
     using (servicebaseEntities sdb = new servicebaseEntities())
     {
         try
         {
             int tmp = Int32.Parse(searchFilter);
             var query = from c in serviceDB.customers
                         where c.postcode == tmp
                         select c;
             tmp4 = query.ToList();
         }
         catch
         {
         }
         finally
         {
             sdb.Dispose();
         }
         return tmp4;
     }
 }
        public List<servicetypes> getServicetypes()
        {
            List<servicetypes> rtnServicetypes = new List<servicetypes>();

            using (servicebaseEntities stb = new servicebaseEntities())
            {
                try
                {
                    var query = (from s in stb.servicetypes
                                select s);
                    rtnServicetypes = query.ToList();
                }
                catch
                {

                }

                finally
                {
                    stb.Dispose();
                }

                return rtnServicetypes;
            }
        }