//Update User
        public async Task <ServerResponse> Update(UserDetails userInfo)
        {
            var response = new ServerResponse()
            {
                Success      = false,
                ErrorMessage = string.Empty
            };

            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                using (var cmd =
                           new SqlCommand(
                               "UPDATE UserTable SET Firstname = @name, Surname = @surname, DOB = @dob, Gender = @gender, Mobile = @mobile, Email = @email, WorkMobile = @work, DateUpdated = @dateupdated WHERE UserId = @userid",
                               con))
                {
                    cmd.Parameters.AddWithValue("@name", userInfo.FirstName);
                    cmd.Parameters.AddWithValue("@surname", userInfo.Surname);
                    cmd.Parameters.AddWithValue("@dob", SQLExtentions.IsValidSqlDateTime(userInfo.DOB) ? userInfo.DOB : (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue);
                    cmd.Parameters.AddWithValue("@gender", userInfo.Gender);
                    cmd.Parameters.AddWithValue("@mobile", userInfo.Mobile);
                    cmd.Parameters.AddWithValue("@email", userInfo.Email);
                    cmd.Parameters.AddWithValue("@work", userInfo.WorkMobile);
                    cmd.Parameters.AddWithValue("@userid", userInfo.UserId);
                    cmd.Parameters.AddWithValue("@dateupdated", DateTime.Now);

                    cmd.Connection = con;
                    int result = await cmd.ExecuteNonQueryAsync();

                    if (result == 1)
                    {
                        response.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success      = false;
                response.ErrorMessage = "Failed to make connection: " + ex;
            }
            finally
            {
                con.Close();
            }

            return(response);
        }
        //Insert User
        public async Task <ServerResponse> InsertUserDetails(UserDetails userInfo)
        {
            var response = new ServerResponse()
            {
                Success      = false,
                ErrorMessage = string.Empty
            };

            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                //Check if email is already in use
                SqlCommand validate = new SqlCommand("select count(*) from UserTable where Email = @email", con);
                validate.Parameters.AddWithValue("@email", userInfo.Email);
                int count = Convert.ToInt32(validate.ExecuteScalar());

                if (count == 0)
                {
                    using (var cmd =
                               new SqlCommand(
                                   "insert into UserTable(UserId,Firstname,Surname,DOB,Gender,Mobile,Email,WorkMobile,DateCreated,DateUpdated) values (@userid,@firstname,@surname,@dob,@gender,@mobile,@email,@work_mobile,@datecreated,@dateupdated)",
                                   con))
                    {
                        cmd.Parameters.AddWithValue("@userid", Guid.NewGuid().ToString("N"));
                        cmd.Parameters.AddWithValue("@firstname", userInfo.FirstName);
                        cmd.Parameters.AddWithValue("@surname", userInfo.Surname);
                        cmd.Parameters.AddWithValue("@dob", SQLExtentions.IsValidSqlDateTime(userInfo.DOB) ? userInfo.DOB : (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue);
                        cmd.Parameters.AddWithValue("@gender", userInfo.Gender);
                        cmd.Parameters.AddWithValue("@mobile", userInfo.Mobile);
                        cmd.Parameters.AddWithValue("@email", userInfo.Email);
                        cmd.Parameters.AddWithValue("@work_mobile", userInfo.WorkMobile);
                        cmd.Parameters.AddWithValue("@datecreated", DateTime.Now);
                        cmd.Parameters.AddWithValue("@dateupdated", DateTime.Now);

                        int result = await cmd.ExecuteNonQueryAsync();

                        if (result == 1)
                        {
                            response.Success = true;
                        }
                    }
                }
                else
                {
                    response.Success      = false;
                    response.ErrorMessage = "Email already in Use";
                }
            }
            catch (Exception ex)
            {
                response.Success      = false;
                response.ErrorMessage = "Failed to make connection: " + ex;
            }
            finally
            {
                con.Close();
            }

            return(response);
        }