//Determines a customer id public void CreateCustomerId() { //creating database connection using (var ctx = new DPACEntities()) { string finalVal = ""; string idNameFormat = ParseNameForCode(this.FirstName, this.LastName);//Parses to give format i.e. PIXAI var customerNumCode = ctx.GetIvorPixabajCustomerCode(idNameFormat).SingleOrDefault(); //if nada was found, it would signify a new customer if (customerNumCode == null) { finalVal = idNameFormat + "00001"; } else { string tempNumCode = "00000"; //default num code string num = customerNumCode.NextID; //value need to string newNumCode = tempNumCode.Substring(0, tempNumCode.Length - num.Length); finalVal = idNameFormat + newNumCode + (Int32.Parse(num) + 1); } this.ParsedName = idNameFormat; this.CustomerId = finalVal; //return finalVal; } }